結果

問題 No.737 PopCount
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-15 16:26:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,040 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 164,520 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 03:43:02
合計ジャッジ時間 2,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr long long mod = 1e9+7;
constexpr long long inv2 = 5e8+4;

int main(){
    long long N;
    cin >> N;
    long long ans = 0;
    long long b = 1LL;
    while (N >= b){
        long long bm = b % mod;
        long long q = (N + 1LL) / b;
        long long r = (N + 1LL) % b;
        long long p = q / 2;
        long long pm = p % mod;
        long long qm = q % mod;
        long long rm = r % mod;
        long long bp = bm * pm % mod;
        long long inc = bp * bp % mod;
        ans = (ans + inc) % mod;
        inc = (bm + mod - 1LL) % mod;
        inc = inc * bm % mod;
        inc = inc * inv2 % mod;
        inc = inc * pm % mod;
        ans = (ans + inc) % mod;
        if (q % 2LL == 1LL){
            inc = (bm * qm) % mod;
            inc = (inc * rm) % mod;
            ans = (ans + inc) % mod;
            inc = ((rm * (rm + mod - 1LL)) % mod * inv2) % mod;
            ans = (ans + inc) % mod;
        }
        b *= 2LL;
    }
    cout << ans << endl;
    return 0;
}
0