Codeforces Round #384 (Div. 2) B Chloe and the sequence
来源:互联网 发布:大连u盘数据恢复公司 编辑:程序博客网 时间:2024/06/05 04:30
B. Chloe and the sequence
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.
题目大意:问第n个数列的第m个数是什么
n=1时数列为 1
n=2时数列为 1 2 1
n=3时数列为 1 2 1 3 1 2 3
可以知道当为2的n-1次方时可以得到最大值
#include<stdio.h>#include<string.h>int main(){ long long n,m; long long a[51]; a[0]=1; for(int i=1;i<=50;i++) a[i]=a[i-1]*2; scanf("%lld%lld",&n,&m); int flog=0; while(!flog) for(int i=0;i<=n;i++) { if(a[i]>m) m-=a[i-1],i=0; if(a[i]==m) { printf("%d\n",i+1); flog=1; break; } }}
- Codeforces Round #384 (Div. 2) B Chloe and the sequence
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence
- Codeforces Round #384(Div. 2)B. Chloe and the sequence【思维+lowbit】
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence 找规律
- Codeforces Round #384 (Div. 2) 743B Chloe and the sequence
- Codeforces Round #384 B. Chloe and the sequence
- Codeforces 743B Chloe and the sequence
- 743B. Chloe and the sequence codeforces
- Codeforces 743B-Chloe and the sequence
- ***CodeForces - 743B Chloe and the sequence
- Chloe and the sequence CodeForces
- Chloe and the sequence CodeForces
- B. Chloe and the sequence
- 【47.40%】【codeforces 743B】Chloe and the sequence
- codeforces 743 B Chloe and the sequence(递归)
- codeforces 743 B. Chloe and the sequence (规律题)
- Codeforces Round #384(Div. 2)D. Chloe and pleasant prizes【树形dp】
- Codeforces Round #384 (Div. 2)-D. Chloe and pleasant prizes(线段树)
- Eclipse 简介和插件开发
- java--FilenameFilter文件过滤器
- Unix指令
- UVA - 11604 General Sultan
- Android小程序:如何给通过WindowManager的addView添加的view设置动画
- Codeforces Round #384 (Div. 2) B Chloe and the sequence
- Android常用名令集锦(图文并茂)!
- codeforces 743 B Chloe and the sequence(递归)
- caffe vs2013 win7 64编译
- 从BroadcastReceiver中anr重新认识
- CoreData 之 magicRecoard的使用
- 【计算机视觉】BING: Binarized Normed Gradients for Objectness Estimation at 300fps
- 关于mysql与sqlserver数据同步中的一次Incorrect string value: '\xA4\x9F2003...' for column异常
- 【Java】web在线打开PDF(pdf.js教程)