Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional

How many pairs of integers (x, y) with 1 <= x < y <= 12 satisfy x XOR y = x + y?

  1. A. 25
  2. B. 23
  3. C. 22
  4. D. 43

Correct answer: B. 23

x + y = (x XOR y) + 2(x AND y), so equality holds exactly when x AND y = 0, meaning no shared set bits. Checking the pairs directly confirms the count.

More Coding Interview Problems questions

Exams that ask this topic