bool checkPerfectNumber(int num){
if (num < 2) return false;
int sum=0,i;
for (i=1; i<=sqrt(num); i++)
{
if (num % i==0)
{
sum += (i != sqrt(num) && i != 1) ? i+num/i : i;
}
}
return sum == num;
}
原文:https://www.cnblogs.com/ganxiang/p/13656667.html