507. 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 n, return true ifn is a perfect number, otherwise returnfalse.
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 = 6
Output: trueExample 3:
Input: num = 496
Output: trueExample 4:
Input: num = 8128
Output: trueExample 5:
Input: num = 2
Output: falseConstraints:
1 <= num <= 108
# @lc code=start
using LeetCode
perfect_number(num::Int) = num in [6, 28, 496, 8128, 33550336]
# @lc code=endperfect_number (generic function with 1 method)
This page was generated using DemoCards.jl and Literate.jl.