結果

問題 No.737 PopCount
ユーザー りあんりあん
提出日時 2018-09-28 23:06:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 647 bytes
コンパイル時間 3,962 ms
コンパイル使用メモリ 197,712 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 12:03:11
合計ジャッジ時間 4,394 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int M = 1000000007;
const int iM = 500000004;

int main() {
    long long n;
    cin >> n;
    long long sum = 0;
    for (int i = 0; n >> i; ++i) {
        long long c = (n + 1) / (1L << (i + 1)) * (1L << i);
        long long m = (c * 2 - 1) % M * (c * 2 % M) % M * iM % M;
        sum = (sum + (m + c % M * ((1L << i) % M) % M) % M * iM % M) % M;
        if ((n + 1) % (1L << (i + 1)) >= (1L << i)) {
            sum = (sum + (c * 2 + (1L << i) % M + n) % M * ((n - c * 2 - (1L << i) + 1) % M) % M * iM) % M;
        }
    }
    cout << sum << "\n";
    return 0;
}
0