結果
| 問題 | No.822 Bitwise AND | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 21:37:25 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,350 bytes | 
| コンパイル時間 | 492 ms | 
| コンパイル使用メモリ | 82,380 KB | 
| 実行使用メモリ | 76,612 KB | 
| 最終ジャッジ日時 | 2025-06-12 21:39:55 | 
| 合計ジャッジ時間 | 6,827 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 1 -- * 16 | 
ソースコード
def count_pairs(N, K):
    if N == 0 and K >= 1:
        return "INF"
    
    count = 0
    max_bit = N.bit_length() + K.bit_length()  # 足够大的位数
    
    for d in range(K + 1):
        if d == 0:
            a = 0
            x = N | a
            y = x
            if x & y == N and y - x == d:
                count += 1
            continue
        
        # 生成所有可能的 a,使得 a & (a + d) == 0
        # 由于我们需要考虑 a 可能非常大,我们采用位运算的方法
        # 但是,在本题中,由于 K ≤ 300,我们可以用暴力枚举 a 的方法,但需要限制 a 的范围
        # 这里,我们假设 a 的范围不超过 2^max_bit,这可能在实际应用中需要优化
        for a in range(0, 1 << max_bit):
            a_plus_d = a + d
            if (a & a_plus_d) != 0:
                continue
            x = N | a
            y = N | a_plus_d
            if x > y:
                continue
            if (x & y) != N:
                continue
            if y - x != d:
                continue
            count += 1
    return count
# 读取输入
import sys
def main():
    N, K = map(int, sys.stdin.readline().split())
    if N == 0 and K >= 1:
        print("INF")
    else:
        res = count_pairs(N, K)
        print(res)
if __name__ == "__main__":
    main()
            
            
            
        