D题,不理解错在哪里,只能过55%的数据

import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static StreamTokenizer sk = new StreamTokenizer(br);
    static int MOD = (int)1e9 + 7;
    public static void main(String[] args) throws Exception {
        int T = nextInt();
        for (int cases = 0; cases < T; cases ++ ) {
            long n = nextLong();
            long maxh = 0;
            while ((1L << maxh) - 1 <= n) {
                maxh ++ ;
            }
            maxh -- ;
            long ans = 0L;
            for (long i = 1L; i <= maxh; i ++ ) {
                ans = (ans + (maxh - i + 1) * (1L << (i - 1))) % MOD;
            }

            long a = 1L;
            long surplus = n - ((1L << maxh) - 1);
            while (surplus != 0) {
                if ((surplus & 1) != 0) {
                    ans = (ans + (a << 1) - 1) % MOD;
                }
                a = (a << 1) % MOD;
                surplus >>= 1;
            }
            pw.println(ans);
        }
        pw.flush();
    }


    static int nextInt() throws Exception {
        sk.nextToken();
        return (int)sk.nval;
    }

    static long nextLong() throws Exception {
        sk.nextToken();
        return (long) sk.nval;
    }

    static String nextString() throws Exception {
        sk.nextToken();
        return sk.sval;
    }
}

全部评论

相关推荐

冰激凌好吃:谁知盘中餐,谁都不一般😗
点赞 评论 收藏
分享
沐芷凌曦:这简历数分别指望了,数分最基本的SQL能力你的经历是完全没办法佐证的,而且简历排版极其混乱。你的奖项为什么要写具体的项目内容;教育经历为什么要写你在什么课学到了什么东西,这些都应该是在专业技能里的;专业技能里你又把项目的内容放了进来,而且专业技能你又在强调ETL,如果说你确定要把ETL作为你专业技能的主体那你的经历为什么不能重点佐证呢;反而项目经历你项目等于你调用PyEcharts做了一个看板,就是最基本的课程设计,也是没办法佐证你对PyEcharts的掌握程度,而且没有说具体用什么技术做了什么东西中间做了什么最终得到了什么结果。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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