結果

問題 No.2939 Sigma Popcount Problem
ユーザー InTheBloom
提出日時 2024-10-18 23:08:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 85,680 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-18 23:08:06
合計ジャッジ時間 4,435 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main () {
    int T; cin >> T;
    for (int z = 0; z < T; z++) {
        ll N; cin >> N;
        // 主客転倒して各bitが何回数えられるかを考える。
        ll ans = 0;
        for (int i = 0; i < 60; i++) {
            ll add = 0;

            ll rep = (N + 1) / (1LL << (i + 1));
            add += rep * (1LL << i);

            // 余り
            ll rem = (N + 1) % (1LL << (i + 1));
            add += max(0LL, rem - (1LL << i));

            ans += add;
        }

        cout << ans << "\n";
    }
}
0