Leetcode 507 Solution
This article provides solution to leetcode question 507 (perfect-number)
Access this page by simply typing in "lcs 507" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/perfect-number
Solution
class Solution {
public:
bool checkPerfectNumber(int num) {
if (num == 1)
return false;
int limit = sqrt(num);
int sum = 1;
for (int i = 2; i <= limit; i++)
{
if (num % i == 0)
sum += i + num / i;
}
return sum == num;
}
};