ProgrammingHardTCS NQT · Accenture
Smallest n such that n! has at least 5 trailing zeros is searched for by the procedure below, where z(n) is the number of factors 5 in n! (sum of n div 5^k). What is printed as n?
Smallest n such that n! has at least 5 trailing zeros is searched for by the procedure below, where z(n) is the number of factors 5 in n! (sum of n div 5^k). What is printed as n?
n = 1
while z(n) < 5
n = n + 1
end while
Print n- A. 8
- B. 20
- C. 9
- D. 25
Correct answer: D. 25
n = 25 is the first value with five factors of 5 (25 contributes two). Using factors of 2 gives 8, using only the first power gives 20, and confusing trailing zeros with the size of the factorial stops at 9.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- A number N = 1296 is reduced by the procedure below, which divides by the smallest prime factor each time it can and keeps a count of the…
- The procedure below counts the numbers from 1 to 1000 whose digit sum is exactly 5. It uses digit-sum by repeated division. What is…
- The procedure below finds how many integers x with 1 <= x <= 200 satisfy x^2 mod 13 == 1. What is printed? count = 0 for x = 1 to 200 if…
- The procedure below computes the value of the sum 1^2 + 2^2 + ... + 10^2 using the formula n(n+1)(2n+1)/6 for n = 10, and then the loop…
- Count the integers n with 1 <= n <= 1000 that are divisible by 7 but NOT divisible by 11. The procedure below does this with one loop…
- Count the integers n with 1 <= n <= 500 that are divisible by 4 or by 6. The procedure below uses a single loop. What is printed? count =…