Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the sum of the divisors of 28 (a perfect number)?

Problem: What is the sum of the divisors of 28 (a perfect number)?
print(sum(d for d in range(1, 29) if 28 % d == 0))
What is printed?
  1. A. 28
  2. B. 7
  3. C. 6
  4. D. 56

Correct answer: D. 56

The divisors of 28 are 1, 2, 4, 7, 14 and 28, which sum to 56 (twice 28, since 28 is perfect). Leaving out 28 itself (proper divisors) gives 28, stopping the loop at √28 gives 1 + 2 + 4 = 7, and counting divisors instead of summing them gives 6.

More Coding Interview Problems questions

Exams that ask this topic