题解 | 小q的数列

小q的数列

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

 f(n)的值等于n的二进制表示中1的个数

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T=in.nextInt();
        while(T-->0){
            long n=in.nextLong();
            long k=(1L<<Long.bitCount(n))-1;
            System.out.println(Long.bitCount(n)+" "+k);
        }
    }
}

全部评论

相关推荐

求个付费实习岗位:这种就是吃满时代红利又没啥技术水平,只能靠压力学生彰显优越感的老登,别太在意了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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