ProgrammingVery hardCAT · MBA placement
The number of trailing zeros of 1000! equals the power of 5 in 1000!, which is the sum of floor(1000 / 5^k) for k = 1, 2, 3, ... The procedure below computes it. What is printed?
The number of trailing zeros of 1000! equals the power of 5 in 1000!, which is the sum of floor(1000 / 5^k) for k = 1, 2, 3, ... The procedure below computes it. What is printed?
count = 0; p = 5
while p <= 1000
count = count + 1000 div p
p = p * 5
end while
Print count- A. 397
- B. 1098
- C. 200
- D. 249
Correct answer: D. 249
The factor 5 appears 200 + 40 + 8 + 1 = 249 times, which is the trailing zero count of 1000!. Counting factors of 2 instead gives a much larger number, adding 5 to p instead of multiplying gives 1098, and stopping after the first power gives 200.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The least common multiple of the integers 1 through 10 is computed by folding lcm(a, b) = a b div gcd(a, b) from L = 1. The procedure…
- Count the three-digit numbers (100 to 999) in which every digit is odd. The procedure below uses a loop over the numbers and checks each…
- Count the pairs (i, j) with 1 <= i <= j <= 10 for which the product i j is a perfect square. The procedure below does this with two nested…
- The procedure below finds the largest prime less than 100 by testing each candidate from 99 down to 2 for divisibility by 2 up to its…
- The procedure below sums the integers from 1 to 100 that are NOT divisible by 2 and NOT divisible by 3. What is printed? total = 0 for n =…
- Count the numbers n with 1 <= n <= 100 such that both n and n + 2 are prime (twin primes, lower member n). The procedure below checks…