poj 1528 Perfection

题目链接:http://poj.org/problem?id=1528

题目大意:输入一个数n,然后求出约数的和sum,在与这一个数n进行比较,如果sum>n,则输出ABUNDANT,如果sum=n,则输出PERFECT,否则,输出DEFICIENT!

注意1的结果是DEFICIENT,0的结果是END OF OUTPUT!

 1 #include <iostream>

 2 #include <cstdio>

 3 using namespace std;

 4 int main ()

 5 {

 6     int n;

 7     cout<<"PERFECTION OUTPUT"<<endl;

 8     while(cin>>n)

 9     {

10         if(n==0)

11         {

12             cout<<"END OF OUTPUT"<<endl;

13             break;

14         }

15         if(n==1)

16         {

17             printf("%5d  DEFICIENT\n",n);

18             continue;

19         }

20         int sum=1;

21         for (int i=2; i<n; i++)

22             if (n%i==0)

23                 sum+=i;

24         if(sum<n) printf("%5d  DEFICIENT\n",n);

25         else if(sum==n) printf("%5d  PERFECT\n",n);

26         else printf("%5d  ABUNDANT\n",n);

27     }

28     return 0;

29 }

 

你可能感兴趣的:(poj)