Sample Input
15 28 6 56 60000 22 496 0
Sample Output
PERFECTION OUTPUT
15 DEFICIENT
28 PERFECT
6 PERFECT
56 ABUNDANT
60000 ABUNDANT
22 DEFICIENT
496 PERFECT
END OF OUTPUT
#include<cstdio>
#include<cstring>
#include<stack>
#include<iostream>
using namespace std;
int sum(int m){
int sum = 0;
for(int i = 1; i <= m/2; i++){
if(m % i == 0) sum += i;//做除法运算的时候一定要小心分母是否为0
}
return sum;
};
int main()
{
int n;
cout<< "PERFECTION OUTPUT"<< endl;
while(cin >> n){
if(n == 0) break;
int t = sum(n);
printf("%5d",n);
if(t == n) cout << " PERFECT" << endl;
else if(t > n) cout << " ABUNDANT" << endl;
else cout << " DEFICIENT" << endl;
}
cout << "END OF OUTPUT" << endl;
return 0;
}
1. 原来提前把PERFECTION OUTPUT 输出来也可以AC