ProgrammingHardGoldman Sachs OA · TCS Digital

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer n = 50, c = 0, p = 2
while (p <= n)
    c = c + n / p
    p = p * 2
end while
Print c
  1. A. 47
  2. B. 25
  3. C. 31
  4. D. 12

Correct answer: A. 47

Legendre's formula counts the factors of 2 in 50!: 25 + 12 + 6 + 3 + 1 = 47 (so 50! ends in 47 zero bits).

More Pseudocode and Code Tracing questions

Exams that ask this topic