Codeforces Round #384(Div. 2)B. Chloe and the sequence【思维+lowbit】

B. Chloe and the sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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.


题目大意:

初始序列只有一个数字1,接下来我们需要进行(n-1)次操作,接下来我们每一次都需要在序列尾部加上一个没出现过的最小正整数.再接下来将之前的序列复制一次放在序列末尾,让我们判断进行了n-1次操作之后,第k个位子上的数字是多少。


思路:


1、每次增加的序列长度肯定是和2的倍数相关的,那么我们肯定要把思路矛头指向二进制上来。


2、那么我们分析这样一个序列:

1 2 1 3 1 2 1 4 1 2 1 3 1 2 1.

其中,我们先分析1 2 3 4,其所在位子为1,2,4,8.都是2的整数次方,对应我们将位子转化成二进制:

0

10

100

1000

很显然,对于这个位子上的值,就是逆序来看,第一个1出现的位子。

那么接下来我们对于这个观察得到的结果类推到其他数字以及其位子上来看,其结果是正确的。


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
int a[60];
#define ll __int64
int main()
{
    ll n,k;
    while(~scanf("%I64d%I64d",&n,&k))
    {
        int cnt=0;
        while(k)
        {
            a[cnt++]=k%2;
            k/=2;
        }
        /*
        for(int i=0;i<cnt;i++)
        {
            printf("%d",a[i]);
        }
        printf("\n");*/
        int output=0;
        for(int i=0;i<cnt;i++)
        {
            output++;
            if(a[i]==1)
            {
                break;
            }
        }
        printf("%d\n",output);
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值