Chloe and the sequence

題目地址

題目大意:按照他的那個創造數組的方式,數第k個數是幾。

思路:看他給的數組例子,會發現奇數時都是1,當去處1時奇數又都是2了,以此類推。


#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define ll long long
using 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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章