Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学

时间:2024-01-13 18:02:20

B. Chloe and the sequence

题目链接

http://codeforces.com/contest/743/problem/B

题面

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!

输入

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

输出

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

样例输入

3 2

样例输出

2

题意

假设现在的数列是a,那么在a的背后放一个最小的没出现过的整数,然后再把a重复的放在后面。

然后现在问你p位置是什么

题解

直接按照题意模拟迭代下去也可以……

但实际上就是这个p数字的二进制最小的1的位数的位置。

代码

#include<bits/stdc++.h>
using namespace std; long long n,p;
int main()
{
scanf("%lld%lld",&n,&p);
cout<<log2(p&(-p))+1<<endl;
}