Data Structures & AlgorithmsHardCodeforces Div2 B · factorial factors
Problem: Find the smallest positive integer n such that n! has at least 6 trailing zeros. Run the code.
Problem: Find the smallest positive integer n such that n! has at least 6 trailing zeros. Run the code.
def zeros(n):
c = 0
p = 5
while p <= n:
c += n // p
p *= 5
return c
n = 1
while zeros(n) < 6:
n += 1
print(n)What is printed?- A. 20
- B. 30
- C. 24
- D. 25
Correct answer: D. 25
Trailing zeros of n! depend only on factors of 5. 20! has 4 zeros and 25! has 25 // 5 + 25 // 25 = 6 zeros, so 25 is the first n that works.
More Coding Interview Problems questions
- 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 =…
- Problem: What does the following print? It counts distinct values in each window of size 3. python from collections import Counter a = [1…
- Problem: Rotate the array [1, 2, 3, 4, 5, 6, 7] to the right by k = 3 using the three-reversal method. What is printed? python a = [1, 2…