C++ 代码
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
int x;
cin>>x;
int s=0;
for(int i=1;i*i<=x;i++) //i*i<x,表示算一半就可以
if(x%i==0){ //代码优化 这里从1开始数是小的
if(i < x ) s += i; //排除
if(i != x/i && x/i<x) s+=x/i; //排除平方数,加上另一半对应的数
}
if(s==x) cout<<x<<" is perfect"<<endl;
else cout<<x<<" is not perfect"<<endl;
}
return 0;
}