結果

問題 No.680 作れる数
ユーザー convexineq
提出日時 2021-03-13 17:55:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 53,716 KB
最終ジャッジ日時 2024-10-15 08:26:47
合計ジャッジ時間 1,925 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n):
    def ok(k,s,n):
        if s==n: return True
        L = R = s
        for i in range(35):
            L += 2*k
            R += 2*k+(2**(i+1)-1)
            if L <= n <= R:
                return True
            if n < L:
                return False
            k *= 2
        return False
    
    if n <= 1: return True
    k = s = 1
    cc = 0
    while True:
        if s == n: return True
        if s > n: return False
        for c in range(2):
            kk = 2*k+c
            if ok(kk,s+kk,n):
                k = kk
                s += kk
                break
        else:
            return False

n = int(input())
print("YES" if f(n) else "NO")
0