結果

問題 No.737 PopCount
コンテスト
ユーザー rpy3cpp
提出日時 2019-05-15 13:48:52
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 897 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,011 ms
コンパイル使用メモリ 179,540 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 08:41:56
合計ジャッジ時間 1,802 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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