Perfect Number

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly. Given an integer num, return true if num is a perfect number, otherwise return false.

30:00

Perfect Number
easy
Free written solution
Topics
Companies

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly. Given an integer num, return true if num is a perfect number, otherwise return false.

Example 1:
Input: {"num":28}
Output: true
Constraints:
  • 1≤num≤1081 \leq \text{num} \leq 10^8

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"num":28}

A perfect number equals the sum of its proper divisors (every divisor except itself). Is 28 one?

candidates i = 2 .. ⌊√28⌋ = 5

2
3
4
5

divisor pairs: i × (num / i) = 28

total = 0

target num = 28

■ small divisor i

■ partner num / i

| target

Variables
VariableValue
num28
DepthFunction Call
Stack empty
0/12