![]() |
VOOZH | about |
A number is a perfect number if it is equal to the sum of its proper divisors, that is, the sum of its positive divisors excluding the number itself. Find whether a given positive integer n is perfect or not.
Examples:
Input: n = 15
Output: false
Explanation: Divisors of 15 are 1, 3 and 5. Sum of divisors is 9 which is not equal to 15.
Input: n = 6
Output: true
Explanation: Divisors of 6 are 1, 2 and 3. Sum of divisors is 6.
Table of Content
A simple Solution is to go through every number from 1 to n-1 and check if it is a divisor. Maintain sum of all divisors. If sum becomes equal to n, then return true, else return false.
false
An efficient Solution is to go through numbers till square root of n. If a number 'i' divides n, then add both 'i' and 'n/i' .
false
Interesting facts About Perfect Number
1) Every even perfect number is of the form 2pā1ā
(2pā1) , where 2pā1 is a prime number.
2) It is unknown whether there are any odd perfect numbers.