PerfectionTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2027 Accepted Submission (s): 1213
Problem Descriptionfrom The article number theory in the 1994 Microsoft Encarta: "If A, B, c is integers such that a = BC , A is called a multiple of B or of C, and B or C is called a divisor or factor of a. If c is not 1/-1, and B is called a proper divisor of a. Even integers, which include 0, is multiples of 2, for example,-4, 0, 2, 10; An odd integer is a integer is not even, for example,-5, 1, 3, 9. A perfect number is a positive an integer that's equal to the sum of the-its positive, proper divisors; For example, 6, which equals 1 + 2 + 3, and, which equals 1 + 2 + 4 + 7 + +, is perfect numbers. A positive number that is not perfect are imperfect and is deficient or abundant according to whether the sum of its positi ve, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; Proper divisors 1, 2, 3, 4, 6, is abundant. "
Given a number, determine if it is perfect, abundant, or deficient.
Inputa List of N positive integers (none greater than 60,000), with 1 < n < 100. A 0 'll mark the end of the list.
Outputthe first line of output should read perfection output. The next N lines of output should list for each input integer whether it was perfect, deficient, or abundant, as shown in t He example below. Format counts:the echoed integers should be right justified within the first 5 spaces of the output line, followed by Blank spaces, followed by the description of the integer. The final line of output should read END of output.
Sample Input
15 28 6 56 60000 22 496 0
Sample Output
Perfection OUTPUT deficient PERFECT 6 PERFECT ABUNDANT60000 Abundant deficient 496 PERFECTEND of OUTPUT
To find all true factors of a number and the size of this number, 2015,7,24
#include <stdio.h>int f (int n) {int sum=0;for (int i=2;i<=n/2;i++) {if (n%i==0) sum+=i;if (sum>n) break;} if (sum+1>n) return 2;//start to forget to add 1,,, find a half-day error, wipe the else if (sum+1==n) return 1; else return 0; } int main () {int m,i,k=0; int a[60005]; while (scanf ("%d", &m), m) {a[k++]=m;} printf ("Perfection output\n"); for (i=0 ; i<k;i++) {if (f (a[i]) ==1) printf ("%5d perfect\n", A[i]), else if (f (a[i]) ==0) printf ("%5d deficient\n", a [i]); else printf ("%5d abundant\n", A[i]);} printf ("END of output\n"); return 0;
HDU 1323 Perfection