题解 | 小q的数列

小q的数列

https://www.nowcoder.com/practice/8ea1e0d996f64e15961ae42e658a04a7

#include <iostream>
using namespace std;
long long fx(long long x)
{
    if(x==0) return 0;
    if(x==1) return 1;
    return fx(x/2)+fx(x%2);
}
int main() {
    int t;
    cin>>t;
    while(t--)
    {
        long long x;
        cin>>x;
        long long c=fx(x);
        cout<<c<<" "<<(1LL<<c)-1<<endl;;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务