382-perfection
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem &problem=318
From the article number theory in the 1994 Microsoft Encarta: ' If a,b, c are integers-such that's = BC, A is called a mul Tiple ofb or of C, and B or C is called a divisor or factor ofa. If C is not
, b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example,-4, 0, 2, 10; An odd the integer is ' is ' isn't even, for example,-5, 1, 3, 9. A perfect number is a positive integer, which equal to the sum of "all" its positive, proper divisors; For example, 6, which equals 1 + 2 + 3, and, which equals 1 + 2 + + 4 + 7 +, are perfect numbers. A positive number that are not perfect are imperfect and are deficient or abundant according to whether the sum of it Positi ve, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, are deficient; Proper divisors 1, 2, 3, 4, 6, is abundant. "
Problem Statement
Given a number, determine if it is perfect, abundant, or deficient.
Input
A List of N positive integers (none greater than 60,000) with 1 < n < 100. A 0 would mark the end of the list.
Output
The line of output should read perfection output. The next N lines of output should list for each input integer whether it are perfect, deficient, or abundant, as shown in t He example below. Format counts:the echoed integers should is right justified within the ' the ' 5 spaces of the output line, followed by two Blank spaces, followed by the description of the integer. The final line of output should readend of output.
Sample Input
15 28 6 56 60000 22 496 0
Sample Output
Perfection OUTPUT deficient PERFECT
6 PERFECT abundant
60000 abundant deficient
496 PERFECT
end of OUTPUT
Full code, O (√n) Complexity:
/*0.019s*/
#include <cstdio>
#include <cmath>
int main ()
{
int n,m,i, sum;
Puts ("Perfection OUTPUT");
while (scanf ("%d", &n), N)
{
m = (int) sqrt (n), sum = 1;
for (i = 2; I <= m; ++i)
if (n% i = = 0) Sum + = i + n/i;
if (m * m = = N) sum = m;
printf ("%5d ", n);
if (sum < n) puts ("deficient");
else if (sum > N) puts ("abundant");
Else puts ("PERFECT");
}
Puts ("End of OUTPUT");
}
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/