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()