The Perfect Number problem asks whether a positive integer is "perfect" — equal to the sum of all its proper divisors (divisors excluding the number itself). For example, 28 = 1+2+4+7+14. This easy coding problem tests efficient divisor enumeration. The math interview pattern is demonstrated.
Microsoft, Meta, Amazon, Google, and Bloomberg ask this as a math warmup that tests divisor enumeration. The key optimization: iterate only up to √n to find divisor pairs in O(√n) time instead of O(n).
Divisor enumeration up to √n. For i from 2 to √n: if i divides n, add both i and n/i to the divisor sum. Handle the case i == n/i (perfect square, don't add twice). Start with sum=1 (the divisor 1 is always included). Check if sum == n. Return false for n=1 (1 is not perfect).
n=28. Sum starts at 1.
n=6. Sum=1+2+3=6==6. Return true.
Divisor enumeration up to √n is a fundamental number theory optimization. Always iterate i from 2 to sqrt(n), adding both i and n/i when i divides n, checking for the perfect square case. Practice this on: "sum of divisors," "count divisors," "perfect number check," "amicable numbers." It's a building block for all divisor-based mathematical problems.