結果

問題 No.737 PopCount
ユーザー Konton7
提出日時 2021-05-04 09:03:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 434 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,148 KB
実行使用メモリ 52,736 KB
最終ジャッジ日時 2024-07-22 23:34:51
合計ジャッジ時間 1,760 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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