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;
}

Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学的更多相关文章

  1. Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

  2. Codeforces Round #384 (Div. 2)D - Chloe and pleasant prizes 树形dp

    D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of ...

  3. Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)

    Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...

  4. Codeforces Round #384 (Div. 2) //复习状压... 罚时爆炸 BOOM _DONE

    不想欠题了..... 多打打CF才知道自己智商不足啊... A. Vladik and flights 给你一个01串  相同之间随便飞 没有费用 不同的飞需要费用为  abs i-j 真是题意杀啊, ...

  5. Codeforces Round #384 (Div. 2)A,B,C,D

    A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #384 (Div. 2) A B C D dfs序+求两个不相交区间 最大权值和

    A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  8. Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)

    传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...

  9. Codeforces Round #384 (Div. 2)D-Chloe and pleasant prizes

    D. Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. JS-for中的i

    var aBtn = document.getElementsByTagName('input');        for( var i=0; i<aBtn.length; i++ ){     ...

  2. ansible 2.2的源码编译安装

    ansible代码下载地址:http://releases.ansible.com/ansible/ # git clone git://github.com/ansible/ansible.git ...

  3. Python 迭代dict 效率

    迭代dict也要讲求效率,不然就要走进性能陷阱 以下三种迭代方式:keys,iterkeys, hashkey import timeit DICT_SIZE = 100 * 100000 testD ...

  4. oracle11g数据库的安装以及安装之后的配置

    1.按照正常的顺序进行安装,然后安装完成后可以对用户进行管理,(设置sys  sysmanager的口令,激活scott的用户并设置新密码) 这一步没什么好多的,关键是进行安装完成之后的配置,这个就比 ...

  5. extjs中form.reset(true)出现的bug修复

    在之前的开发extjs中,用ext.form.panel开发了一个表单,当使用了reset(true)之后,再次使用getRecord()却还是可以得到值,该值为上一次的旧值,查看了api文档,再结合 ...

  6. 如何处理webView跳转

    - (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {    // Give iOS a chance to o ...

  7. C#设计模式(5)——建造者模式(Builder Pattern)

    一.引言 在软件系统中,有时需要创建一个复杂对象,并且这个复杂对象由其各部分子对象通过一定的步骤组合而成.例如一个采购系统中,如果需要采购员去采购一批电脑时,在这个实际需求中,电脑就是一个复杂的对象, ...

  8. C语言 线性表 双向链式结构 实现

    一个双向链式结构实现的线性表 duList (GCC编译). /** * @brief 线性表双向链表结构 * @author wid * @date 2013-10-28 * * @note 若代码 ...

  9. LINQ-to-SQL那点事~利用反射在LINQ-to-SQL环境中实现Ado.net的CURD操作

    回到目录 对于linq to sql提供的CURD操作,给我们的感觉就是简单,容易使用,更加面向对象,不用拼SQL语句了,这些好处都表示在处理单条实体或者集合长度小的情况下,如果有一个1000条的集合 ...

  10. js脚本语言基础和数组

    js和PHP中,字符串赋值:要使用"双引号"或"单引号"引起来:例如:var c="你好"不同类型进行数学运算,要转换,类型转换:强制转换p ...