def main(): import sys N, K = map(int, sys.stdin.readline().split()) if N == 0: if K == 0: print(1) else: print("INF") return if K == 0: print(1) return # Check if N has two consecutive ones in binary representation has_consecutive_ones = False prev_one = False n = N while n > 0: bit = n & 1 if bit == 1: if prev_one: has_consecutive_ones = True break prev_one = True else: prev_one = False n >>= 1 if has_consecutive_ones: print("INF") return # Collect all bits in S (complement of N) bits = [] m = 0 while True: bit = 1 << m if (N & bit) == 0: bits.append(bit) m += 1 if bit > N * 2 and m > 20: # Heuristic to limit bits considered break # Dynamic Programming to count valid pairs from collections import defaultdict dp = defaultdict(int) dp[0] = 1 for bit in bits: new_dp = defaultdict(int) for diff in dp: cnt = dp[diff] # Option 1: ignore the bit new_dp[diff] += cnt # Option 2: add to a (subtract bit) new_diff = diff - bit new_dp[new_diff] += cnt # Option 3: add to b (add bit, if within K) new_diff_add = diff + bit if new_diff_add <= K: new_dp[new_diff_add] += cnt dp = new_dp total = 0 for diff in dp: if 0 <= diff <= K: total += dp[diff] print(total) if __name__ == "__main__": main()