結果

問題 No.2939 Sigma Popcount Problem
ユーザー rlangevin
提出日時 2024-10-18 21:33:03
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 487 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,772 KB
最終ジャッジ日時 2024-10-18 22:17:26
合計ジャッジ時間 4,257 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from functools import lru_cache

@lru_cache(maxsize=None)
def f(n):
    if n == 0:
        return 0
    now = 0
    for i in range(1, 65):
        if 2 ** i - 1 > n:
            break
        now = 2 ** i - 1
    r = n - now
    if r == 0:
        return f(n // 2) * 2 + (n + 1) // 2
    return f(now) + f(r - 1) + r
            
            

T = int(input())
for _ in range(T):
    N = int(input())
    print(f(N))    
0