Data Structures & AlgorithmsModerateTCS NQT · number theory
Problem: How many trailing zeros does 100! have? Run the code that counts factors of 5.
Problem: How many trailing zeros does 100! have? Run the code that counts factors of 5.
n = 100
c = 0
p = 5
while p <= n:
c += n // p
p *= 5
print(c)What is printed?- A. 20
- B. 24
- C. 25
- D. 100
Correct answer: B. 24
Each trailing zero needs a factor 10 = 2 * 5, and 2s are always more plentiful, so counting 5s is enough. 100 // 5 + 100 // 25 = 20 + 4 = 24.
More Coding Interview Problems questions
- Problem: Starting from 27, the Collatz map is n -> n/2 if n is even and n -> 3n+1 if n is odd. How many steps does it take to first reach…
- Problem: Find the smallest positive integer n such that n! has at least 6 trailing zeros. Run the code. python def zeros(n): c = 0 p = 5…
- Problem: Find the length of the longest strictly increasing subsequence of [10, 9, 2, 5, 3, 7, 101, 18] with the O(n log n) tails method…
- Problem: Coins of values 2, 5, 10 and 1 are available with unlimited copies. What is the minimum number of coins summing to 27? Run the…
- Problem: How many ways are there to make change for 100 using coins of 1, 5, 10, 25 and 50 (order does not matter)? Run the code. python…
- Problem: Find the longest palindromic substring length of 'forgeeksskeegfor' by expanding around each centre. python s =…