結果

問題 No.737 PopCount
ユーザー PachicobuePachicobue
提出日時 2018-09-28 23:13:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 194,480 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:01:09
合計ジャッジ時間 3,036 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//=================================
// Created on: 2018/09/28 22:51:11
//=================================
#include <bits/stdc++.h>
using ll = long long;
constexpr ll MOD = 1000000007LL;
constexpr ll HALF = (MOD + 1) / 2;
int main()
{
    ll N;
    std::cin >> N;
    ll d = 1;
    ll ans = 0;
    for (; d <= N; d *= 2) {
        const ll step = d * 2;
        const ll num = (N + 1) / step;
        ll sum = 0;
        if (num >= 1) {
            const ll STEP = (d % MOD) * (step % MOD) % MOD;
            const ll S = (((3 * d - 1) % MOD) * (d % MOD) % MOD) * HALF % MOD;
            const ll T = (S + (num - 1) * STEP % MOD) % MOD;
            sum = ((S + T) * num % MOD) * HALF % MOD;
            const ll A = step * num + d;
            if (A <= N) { (sum += (((A + N) % MOD) * ((N - A + 1) % MOD) % MOD) * HALF % MOD) %= MOD; }
        } else {
            sum = (((N + d) % MOD) * ((N - d + 1) % MOD) % MOD) * HALF % MOD;
        }
        (ans += sum) %= MOD;
    }
    std::cout << ans << std::endl;
    return 0;
}
0