ProgrammingHardTCS NQT · Accenture

The sum of the divisors of N = 28 is computed by the procedure below. A number is perfect when its proper divisors (excluding N) add up to N. What is printed?

The sum of the divisors of N = 28 is computed by the procedure below. A number is perfect when its proper divisors (excluding N) add up to N. What is printed?
s = 0
for i = 1 to N
    if N mod i == 0 then s = s + i
end for
Print s
  1. A. 56
  2. B. 28
  3. C. 27
  4. D. 55

Correct answer: A. 56

The divisors of 28 are 1, 2, 4, 7, 14 and 28, summing to 56. Leaving out N gives 28 (so 28 is perfect), leaving out 1 as well gives 27, and subtracting 1 from the total gives 55.

More Pseudocode and Code Tracing questions

Exams that ask this topic