結果
問題 |
No.2939 Sigma Popcount Problem
|
ユーザー |
|
提出日時 | 2025-02-07 11:33:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 298 ms / 2,000 ms |
コード長 | 777 bytes |
コンパイル時間 | 502 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 97,468 KB |
最終ジャッジ日時 | 2025-02-07 11:33:59 |
合計ジャッジ時間 | 5,502 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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()