Chloe and the sequence

来源:互联网 发布:网络电缆 编辑:程序博客网 时间:2024/06/17 23:23

题目地址

题目大意:按照他的那个创造数组的方式,数第k个数是几。

思路:看他给的数组例子,会发现奇数时都是1,当去处1时奇数又都是2了,以此类推。


#include <cstdio>#include <cstring>#include <iostream>#include <string>#define ll long longusing namespace std;int n;ll k, cnt = 0;int main(){    cin >> n >> k;    while(k)    {          cnt++;        if(k % 2)        {            cout << cnt << endl;            return 0;        }        k /= 2;    }    cout << cnt << endl;    return 0;}


原创粉丝点击