結果

問題 No.737 PopCount
ユーザー Konton7Konton7
提出日時 2021-05-04 09:03:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 1,000 ms
コード長 434 bytes
コンパイル時間 1,262 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 71,484 KB
最終ジャッジ日時 2023-09-30 05:38:11
合計ジャッジ時間 3,016 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,184 KB
testcase_01 AC 76 ms
71,152 KB
testcase_02 AC 75 ms
71,264 KB
testcase_03 AC 76 ms
71,252 KB
testcase_04 AC 76 ms
71,100 KB
testcase_05 AC 76 ms
71,148 KB
testcase_06 AC 75 ms
71,340 KB
testcase_07 AC 73 ms
71,276 KB
testcase_08 AC 75 ms
71,316 KB
testcase_09 AC 75 ms
71,296 KB
testcase_10 AC 75 ms
71,484 KB
testcase_11 AC 75 ms
71,360 KB
testcase_12 AC 76 ms
71,352 KB
testcase_13 AC 74 ms
71,432 KB
testcase_14 AC 75 ms
71,364 KB
testcase_15 AC 76 ms
71,276 KB
testcase_16 AC 77 ms
71,188 KB
testcase_17 AC 77 ms
71,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def rangesum(l, r):
    if r < l:
        return 0
    return (l + r) * (r - l + 1) // 2
    
def getsum(a, d, n):
    return (2 * a + (n - 1) * d) * n // 2
    
mod = 10 ** 9 + 7
n = int(input())
ans = 0
for i in range(70):
    a = 1 << i
    b = 1 << (i + 1)
    c = rangesum(a, b - 1)
    d = 1 << (2 * i + 1)
    e = n // b * b + a
    ans += getsum(c, d, n // b)
    ans %= mod
    ans += rangesum(e, n)
    ans %= mod
print(ans)
0