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- A. 8
- B. 5
- C. 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- 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 =…
- Find the gcd of the array [84, 126, 210, 462] by folding the Euclidean gcd across the elements, starting from 0. The procedure below runs…