Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional

How many integers x with 1 <= x <= 100 are divisible by 3 and have exactly two 1-bits in their binary representation?

  1. A. 12
  2. B. 14
  3. C. 11
  4. D. 21

Correct answer: A. 12

Test both conditions for every x up to 100: exactly two set bits, and divisibility by 3. Counting all numbers with two set bits ignores the divisibility requirement, which is the trap.

More Coding Interview Problems questions

Exams that ask this topic