ProgrammingHardInfosys · Cognizant

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 primes used. What is printed as the total number of prime factors counted with multiplicity?

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 primes used. What is printed as the total number of prime factors counted with multiplicity?
count = 0; m = 1296; d = 2
while m > 1
    while m mod d == 0 do m = m div d; count = count + 1
    d = d + 1
end while
Print count
  1. A. 8
  2. B. 5
  3. C. 4
  4. D. 2

Correct answer: A. 8

1296 = 2^4 * 3^4, which has 8 prime factors counted with multiplicity. Using a single if instead of a while gives 5, printing the final divisor gives 4, and counting distinct primes gives 2.

More Pseudocode and Code Tracing questions

Exams that ask this topic