#507

Perfect Number

pupil · 520 · lc easy +28 · verified · 48.1% accepted · 1,288 likes · top 34%

play →

Description

A positive integer is called perfect when its value equals the sum of all its proper divisors — that is, all divisors except the number itself. A proper divisor of x is any positive integer less than x that divides x without a remainder.

Given an integer n, return true if n is a perfect number, or false otherwise.

Example 1:

Input: num = 28
Output: true
Explanation: 28 = 1 + 2 + 4 + 7 + 14
1, 2, 4, 7, and 14 are all divisors of 28.

Example 2:

Input: num = 7
Output: false

Code

1
2
3