ProgrammingHardCAT · MBA placement
The procedure below sums the prime factors of N = 360 counted with multiplicity (2 counted three times, and so on) by trial division. What is printed?
The procedure below sums the prime factors of N = 360 counted with multiplicity (2 counted three times, and so on) by trial division. What is printed?
s = 0; m = 360; d = 2
while m > 1
if m mod d == 0 then s = s + d; m = m div d
else d = d + 1
end while
Print s- A. 10
- B. 17
- C. 8
- D. 360
Correct answer: B. 17
360 = 2^3 * 3^2 * 5, so counted with multiplicity the prime factors sum to 2+2+2+3+3+5 = 17. Counting each prime once gives 10, halving the total gives 8, and multiplying the factors gives 360.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- A product of ten consecutive numbers 1 x 2 x ... x 10 is computed. The procedure below counts how many of the numbers 1 to 10 are…
- 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!…
- 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…