結果

問題 No.2939 Sigma Popcount Problem
ユーザー kemuniku
提出日時 2024-10-18 22:12:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 620 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 82,764 KB
実行使用メモリ 76,644 KB
最終ジャッジ日時 2024-10-18 22:47:51
合計ジャッジ時間 6,047 ms
ジャッジサーバーID
(参考情報)
judge7 / judge8
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

def count_set_bits_fast(N, x):
    # 2^(x+1)の周期でビットが変化する
    cycle_length = 1 << (x + 1)
    
    # フルサイクルの数
    full_cycles = N // cycle_length
    count_in_full_cycles = full_cycles * (1 << x)
    
    # 残りの部分
    remaining = N % cycle_length
    count_in_remaining = max(0, remaining - (1 << x) + 1)
    
    return count_in_full_cycles + count_in_remaining

T = int(input())
for _ in range(T):
    N = int(input())
    ans = 0
    for i in range(60):
        result = count_set_bits_fast(N, i)
        ans += result
        ans %= 998244353
    print(ans%998244353)
0