Data Structures & AlgorithmsHardICPC regional · number theory
Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code.
Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code.
print(sum(100 // 3 ** k for k in range(1, 6)))What is printed?
- A. 33
- B. 36
- C. 50
- D. 48
Correct answer: D. 48
100 // 3 + 100 // 9 + 100 // 27 + 100 // 81 = 33 + 11 + 3 + 1 = 48. Stopping after the first term gives the trap 33.
More Coding Interview Problems questions
- 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…
- Problem: How many unordered pairs from {1, 2, 3, 4, 5, 6} have XOR equal to 7? Run the code. python from itertools import combinations…
- Problem: How many palindromic substrings of length at least 1 does 'abcba' contain? Run the code. python s = 'abcba' print(sum(1 for i in…
- Problem: What is the smallest positive integer whose decimal digits multiply to 36? Run the search code. python x = 1 while True: p = 1…
- Problem: How many ways are there to place 2 non-attacking rooks on a 3 x 3 board (distinct squares, different rows and different columns…