完全数
这种对称的数在处理数量级上的问题时在i<=的地方进行限制
完全数比较特殊还有数学的思路
100000000 内的完全数有且仅有6,28,496,8128,33550336
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--){
int m;
int sum=1;
cin>>m;
for(int i=2;i<=m/i;i++){
if(m%i==0){
sum+=i;
sum+=m/i;
}
}
if(sum==m&&m!=1) cout<<m<<" is perfect"<<endl;
else cout<<m<<" is not perfect"<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
int m;
int i;
int c=0;
cin>>m;
for( i=2;i<=m/i;i++){
if(m%i==0){
cout<<m<<" is not prime"<<endl;
c=1;
break;
}
}
if(c==0){
cout<<m<<" is prime"<<endl;
}
}
return 0;
}