博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【47.40%】【codeforces 743B】Chloe and the sequence
阅读量:4655 次
发布时间:2019-06-09

本文共 2473 字,大约阅读时间需要 8 分钟。

time limit per test1 second

memory limit per test256 megabytes
inputstandard input
outputstandard output
Chloe, the same as Vladik, is a competitive programmer. She didn’t have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.

Let’s consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n - 1) steps. On each step we take the sequence we’ve got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven’t used before. For example, we get the sequence [1, 2, 1] after the first step, the sequence [1, 2, 1, 3, 1, 2, 1] after the second step.

The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i. e. after (n - 1) steps.

Please help Chloe to solve the problem!

Input

The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n - 1).

Output

Print single integer — the integer at the k-th position in the obtained sequence.

Examples

input
3 2
output
2
input
4 8
output
4
Note
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.

In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.

【题目链接】:

【题解】

如果k==2^(n-1)则直接输出.
否则递归搞一下就可以了。(因为处理的都是相同的问题);
如果在左边k就变成k-2^(n-1);否则还是k.
n的话固定-1;
【完整代码】

#include 
using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%I64d",&x)typedef pair
pii;typedef pair
pll;//const int MAXN = x;const int dx[9] = {
0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {
0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);int n;LL k;LL pre[51];void solve(int n,LL k){ if (k==pre[n-1]) cout << n << endl; else if (k < pre[n-1]) solve(n-1,k); else solve(n-1,k-pre[n-1]);}int main(){ //freopen("F:\\rush.txt","r",stdin); pre[0] = 1; rep1(i,1,50) pre[i] = pre[i-1]*2; rei(n);rel(k); solve(n,k); return 0;}

转载于:https://www.cnblogs.com/AWCXV/p/7626819.html

你可能感兴趣的文章
找工作——JVM内存管理
查看>>
【Flask】在Flask中使用logger
查看>>
好系统重装助手教你如何让win10系统快速开机
查看>>
计算机操作系统概述
查看>>
代理模式
查看>>
Infraware推出Tizen应用生成器Polaris,可转换Android应用至Tizen平台
查看>>
luogu1345 奶牛的电信 (最小割)
查看>>
BZOJ 100题留念
查看>>
BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )
查看>>
Jenkins + GitLab 通过 Webhook 自动触发构建爬坑记录
查看>>
MIPS汇编小贴示
查看>>
linux开机启动
查看>>
BZOJ 1101 [POI2007]Zap 【莫比乌斯反演】
查看>>
SQL Server-The target principal name is incorrect. Cannot generate SSPI context
查看>>
AS3全局与局部坐标转换
查看>>
Java内部类详解
查看>>
初识Twisted(一)
查看>>
linux 软件安装篇
查看>>
Sql server数据库大小写敏感设置
查看>>
JAVA多线程-内存模型、三大特性、线程池
查看>>