Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional

How many integers x with 0 <= x <= 255 have a number of 1-bits that is divisible by 3? (Zero has zero 1-bits, which is divisible by 3.)

  1. A. 86
  2. B. 84
  3. C. 56
  4. D. 85

Correct answer: D. 85

Popcounts 0, 3 and 6 qualify: C(8,0) + C(8,3) + C(8,6) = 1 + 56 + 28 = 85. Leaving out zero gives 84, counting only exactly three 1-bits gives 56, and counting multiples of 3 (a misreading) gives 86.

More Coding Interview Problems questions

Exams that ask this topic