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?
- A. 23
- B. 24
- C. 15
- 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
- Problem: On a line of cells 0–9, a token starts at cell 0. Each second it moves right by 2 if the cell is even, and left by 1 if the cell…
- Problem: Count the pairs (i, j) with 1 ≤ i < j ≤ 12 for which the number i·j is a perfect square.
- Problem: The array [4, 9, 2, 7, 5, 6] is processed by insertion sort (standard insertion into the sorted prefix, shifting larger elements…
- Problem: The matrix [[1,2,3],[4,5,6],[7,8,9]] is traversed by rows, but with each row read alternately left-to-right and right-to-left…
- Problem: Find the number of pairs of indices (i, j), i < j, in the array [1, 3, 2, 4, 3, 5] such that a[i] = a[j] + 1 or a[i] = a[j] − 1.
- Problem: A grid has 3 rows and 4 columns. Starting at (0,0), a move goes right or down, and cells with odd row+column are forbidden. How…