- 历届试题 核桃的数量
第7章:函数 完美数
- 2024-1-22 18:37:14 @
#include <bits/stdc++.h>
using namespace std;
bool IfperfectNum(int x)
{
int y=1;
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
y+=i;
if(i*i !=x) y+=x/i;
if(y>x) return false;
}
}
if(y!=x) return false;
return true;
}
int main()
{
cout<<"0\n";
for(int i=6;i<=10000;i++)
{
if(IfperfectNum(i)) cout<<i<<endl;
}
return 0;
}
0 comments
No comments so far...
Information
- ID
- 640
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 33
- Accepted
- 10
- Uploaded By