結果
| 問題 | No.1465 Archaea | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-03-31 17:34:30 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 40 ms / 2,000 ms | 
| コード長 | 826 bytes | 
| コンパイル時間 | 170 ms | 
| コンパイル使用メモリ | 82,060 KB | 
| 実行使用メモリ | 53,700 KB | 
| 最終ジャッジ日時 | 2025-03-31 17:35:00 | 
| 合計ジャッジ時間 | 1,977 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 20 | 
ソースコード
N, K = map(int, input().split())
if N == 1:
    print("YES" if K >= 0 else "NO")
else:
    found = False
    # Iterate possible m values (number of multiplies)
    for m in range(0, K + 1):
        pow2 = 1 << m
        if pow2 > N:
            break
        residual = N - pow2
        if residual < 0:
            continue
        if residual % 3 != 0:
            continue
        sum_terms = residual // 3
        current = sum_terms
        sum_a = 0
        # Compute minimal sum_a
        for i in range(m + 1):
            exponent = m - i
            coeff = 1 << exponent
            ai = current // coeff
            sum_a += ai
            current %= coeff
            if current == 0:
                break
        if sum_a + m <= K:
            found = True
            break
    print("YES" if found else "NO")
            
            
            
        