結果
| 問題 | No.2939 Sigma Popcount Problem |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-07 11:33:53 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 777 bytes |
| 記録 | |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 85,248 KB |
| 実行使用メモリ | 99,156 KB |
| 最終ジャッジ日時 | 2026-06-27 15:38:08 |
| 合計ジャッジ時間 | 3,544 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
def solve():
import sys
data = sys.stdin.read().split()
if not data:
return
t = int(data[0])
out_lines = []
# 各テストケースを順に処理
for idx in range(1, t + 1):
n = int(data[idx])
ans = 0
i = 0
# n の最大ビット数までループ(n <= 10^12 なので、約40ビット程度)
while (1 << i) <= n:
cycle = 1 << (i + 1)
full_cycles = (n + 1) // cycle
ans += full_cycles * (1 << i)
remainder = (n + 1) % cycle
if remainder > (1 << i):
ans += remainder - (1 << i)
i += 1
out_lines.append(str(ans))
sys.stdout.write("\n".join(out_lines) + "\n")
if __name__ == '__main__':
solve()