結果

問題 No.737 PopCount
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-15 13:48:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 165,472 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 23:29:24
合計ジャッジ時間 2,929 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

constexpr long long mod = 1e9+7;

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