UVa 382 Perfection

 1  #include <stdio.h>
 2  #include <stdlib.h>
 3  #include <iostream>
 4  #include <algorithm>
 5  using namespace std;
 6  void check(int n)
 7  {
 8      int ans=0;
 9      for(int i=1;i<n;i++)
10      {
11          if(n%i==0)
12          {
13              ans+=i;
14          }
15      }
16      if(ans==n) printf("%5d  PERFECT\n",n);
17      else if(n<ans) printf("%5d  ABUNDANT\n",n);
18      else printf("%5d  DEFICIENT\n",n);
19 
20  }
21  int main()
22  {
23      printf("PERFECTION OUTPUT\n");
24      int n;
25      while(cin>>n && n!=0)
26      {
27          check(n);
28      }
29      printf("END OF OUTPUT\n");
30      return 0;

31  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble