#include<iostream>
using namespace std;
int isPerfect(int i)
{
int flag = 0;
int total = 0;
int j;
for(j=1;j<=i/2;j++)
{
if(i%j==0)
{
total += j;
}
}
//cout<<"当前数:"<<i<<"total:"<<total<<endl;
if(total == i)
flag = 1;
return flag;
}
int count(int n)
{
int i = 1,sum = 0;
while(i!= (n+1))
{
sum += isPerfect(i++);
}
return sum;
}
int main()
{
int n;
cin>>n;
cout<<count(n)<<endl;
return 0;
}
华为oj inoc产品部--完全数计算
最新推荐文章于 2016-07-15 20:34:53 发布