Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional
How many integers x with 1 <= x <= 64 have a binary representation (without leading zeros) that reads the same forwards and backwards?
- A. 16
- B. 13
- C. 32
- D. 14
Correct answer: D. 14
A palindrome of length L is fixed by its first ceil(L/2) bits, so lengths 1 to 6 give 1 + 1 + 2 + 2 + 4 + 4 = 14 palindromes. The number 64 (1000000) is not a palindrome, and no 7-bit palindrome is at most 64.
More Coding Interview Problems questions
- Problem: The suffix array of a string is its suffix start indices sorted by the suffix text. What is the value at position 2 (0-based) for…
- Problem: How many topological orders does the DAG with edges 0->2, 1->2, 2->3 on vertices 0..3 have? Run the brute-force code. python from…
- Problem: A row of 5 cells starts as [0, 0, 1, 0, 0]. Each step, every cell becomes the XOR of its two neighbours (cells outside the row…
- Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code. python print(sum(100 // 3…
- Problem: How many collinear triples of points does the 3 x 3 grid {0,1,2}^2 contain? Use the cross-product test below. python from…
- Problem: How many integers x in [1, 60] satisfy x ≡ 2 (mod 3) and x ≡ 3 (mod 4)? Run the code. python print(sum(1 for x in range(1, 61) if…