Check if a Number is Perfect
Given a positive integer n, return true if it is a perfect number and false otherwise. A perfect number equals the sum of its positive proper divisors. A…
Given a positive integer `n`, return `true` if it is a perfect number and `false` otherwise. A perfect number equals the sum of its positive proper divisors. A proper divisor divides `n` exactly and is smaller than `n`. For example, the proper divisors of `6` are `1`, `2`, and `3`, whose sum is `6`.
- `1 ≤ n ≤ 10^6` - `n` is always a positive integer.
Example 1: input n = 6; output true. The proper divisors 1, 2, and 3 sum to 6.
Example 2: input n = 28; output true. The proper divisors 1, 2, 4, 7, and 14 sum to 28.
Example 3: input n = 8; output false. The proper divisors 1, 2, and 4 sum to 7, not 8.
Category: Math. Topic: math. Difficulty: Easy. Patterns: math.