Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 B

Problem: The number 9 is written in base 3 as 100. How many numbers from 1 to 100 have a base-3 representation with no digit 2?

  1. A. 23
  2. B. 24
  3. C. 15
  4. D. 16

Correct answer: A. 23

Numbers with only digits 0 and 1 in base 3 below 100 correspond to binary patterns up to 10201₃; the check finds 23. Including 0 gives 24, banning digit 1 instead gives 15, and stopping at 81 = 10000₃ gives 2⁴ = 16.

More Coding Interview Problems questions

Exams that ask this topic