Ctrl K

Equal to Its Own Divisors

Easy
You get a positive integer n. Add up all of its positive divisors except n itself. Return True if the sum is exactly n, and False otherwise. A divisor of a number is a positive integer that divides it with no remainder. Trying every number up to n is too slow for n up to 10⁸, so think about how to cut the search down.
Example 1
n=6 → True

The divisors of 6 other than itself are 1, 2 and 3, which add up to 6.

Example 2
n=12 → False

1 + 2 + 3 + 4 + 6 = 16, not 12.

Example 3
n=1 → False

1 has no divisors smaller than itself, so the sum is 0.

Constraints
  • 1 ≤ n ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
n=6
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 48 tests on the server, hidden ones included.