BISHI61 小q的数列


思路

这道题本质上是要计算一个数字在二进制下"1"的个数,然后构造出另一个具有相同数量"1"但取值最小的数字。

求解代码

java 复制代码
public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int T = Integer.parseInt(br.readLine().trim());

        while (T-- > 0) {
            String str = br.readLine();
            long n = Long.parseLong(str.trim());

            int c = Long.bitCount(n);
            long k = (1L << c) - 1;
            out.println(c + " " + k);
        }

        out.flush();
        out.close();
        br.close();
    }
相关推荐
Dylan的码园1 小时前
从软件工程师看计算机是如何工作的
java·jvm·windows·java-ee
callJJ1 小时前
Spring AI Tool Calling(工具调用)详解——让大模型拥有“动手能力“
java·人工智能·spring·spring ai·tool calling
南部余额2 小时前
SpringBoot文件上传全攻略
java·spring boot·后端·文件上传·multipartfile
lsx2024062 小时前
XHR.readyState详解
开发语言
游乐码2 小时前
c#静态成员
开发语言·c#
FirstFrost --sy2 小时前
高并发内存池:tcmalloc核心实现
开发语言
彩妙不是菜喵2 小时前
C++:深入浅出讲解=>多态
开发语言·c++
java1234_小锋2 小时前
Java高频面试题:什么是Redis哨兵机制?
java·redis·面试
qq_24218863322 小时前
使用 PyInstaller 打包 Python 脚本为 EXE(教程)
开发语言·python