結果
問題 | No.737 PopCount |
ユーザー |
![]() |
提出日時 | 2020-02-26 23:11:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 30 ms / 1,000 ms |
コード長 | 714 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-10-13 15:34:00 |
合計ジャッジ時間 | 1,533 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% from functools import lru_cache # %% N = int(read()) MOD = 10**9 + 7 # %% @lru_cache(None) def f(N): """return (sum of x*popcount(x), sum of x, sum of popcount(x), sum of 1) for 0 <= x <= N""" if N <= 1: return N, N, N, N + 1 Sxp = 0 Sx = 0 Sp = 0 S1 = 0 # 2x a, b, c, d = f(N // 2) Sxp += 2 * a Sx += 2 * b Sp += c S1 += d # 2x+1 a, b, c, d = f((N - 1) // 2) Sxp += 2 * a + 2 * b + c + d Sx += 2 * b + d Sp += c + d S1 += d return Sxp, Sx, Sp, S1 # %% print(f(N)[0] % MOD)