算法1
C++ 代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x,ans;
cin>>n;
while(n--)
{
cin>>x;
if(x==1)
{
cout<<"1 is not perfect"<<endl;
continue;
}
ans=1;
int t=2;
int f=x;
while(x!=1)
{
int num=0;
while(x%t==0)
{
num=(num+1)*t;
int g=x/t;
if(g%t==0)ans+=g;
x/=t;
}
ans+=num;
t++;
if(t*2>f)break;
}
if(ans==f) cout<<f<<" is perfect"<<endl;
else cout<<f<<" is not perfect"<<endl;
}
return 0;
}