完数


完数时间限制: 1秒      内存限制: 32768 KB的从文章的数量在1994年微软在Encarta理论:如果“,b,c是这样,一个=年,一个被称为B的一个或多个C和B或C或因素称为除数整数答如果c是不是1/-1,B称为A的偶数,其中包括0,适当除数是2的倍数,例如,-4,0,2,10;一个奇数是一个整数,是甚至没有,例如,-5,1,3,9一个完全数是一个正整数,等于其所有积极的,正确的约数的总和;。例如,6,等于1 + 2 + 3, 28,等于1 + 2 + 4 + 7 + 14,是完美的数字。正数,它是不完善,不健全或有缺陷,按是否丰富,其积极,正确的约数之和小于或大于的数字为多。本身这样,9,适当的约数1,3,缺乏,12,适当的约数1,2,3,4,6,丰富“。都有一个编号,确定它是否是完美的,丰富的,或不足。

输入
一个正整数n(无超过60,000以上)名单,1 <? <100。 一个0将标志着列表的末尾。

输出
输出的第一行应该读的完善输出。 接下来的N行输出应该列出每个输入整数,无论??是完美的,不足,或丰富,如下面的例子所示。 格式计数:呼应整数应在第5位的输出线由两个空白的描述之后的整数位,其次,右对齐。 最后一行的输出端的输出应该阅读。

采样输入
15 28 6 56 22 496 0 60000

输出范例
华浩输出   15亏   28完美    6完美   56富足60000丰盛   22亏  496完美会期输出来源: 中大西洋美国1996年提交    状态版权所有@ 2001-2009浙江大学ACM /独立笔会队,保留所有权利。Welcome to ZOJLogin | RegisterHome | Contests | Problems | Forum
Problem SetsInformationSelect ProblemRunsRanklist
ZOJ Problem Set - 1284PerfectionTime Limit: 1 Second      Memory Limit: 32768 KBFrom the article Number Theory in the 1994 Microsoft Encarta: "If a, b, c are 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, 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 integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant."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 will mark the end of the list.

Output
The first line of output should read PERFECTION OUTPUT. The next N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below. Format counts: the echoed integers should be right justified within the first 5 spaces of the output line, followed by two 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   15  DEFICIENT   28  PERFECT    6  PERFECT   56  ABUNDANT60000  ABUNDANT   22  DEFICIENT  496  PERFECTEND OF OUTPUTSource: Mid-Atlantic USA 1996Submit    StatusCopyright @ 2001-2009, Zhejiang University ACM/ICPC Team, All rights reserved.


//完数
//Perfection,Mid-Altlantic USA 1996
#include <stdio.h>

int main()
{
int num[100];
int i = 0;
int j = 0;
while (scanf("%d", &num[i]))
{
if (num[i] == 0)
{
printf(
"PERFECTION OUTPUT\n");
break;
}
i
++;
}
for (j = 0; j<i; j++)
{
if (perfection(num[j]) == 0)
{
printf (
"%4d\tPERFECT\n", num[j]);
}
else if (perfection(num[j]) == -1)
{
printf(
"%4d\tDEFCIENT\n", num[j]);
}
else if (perfection(num[j]) == 1)
{
printf(
"%4d\tABUNDANT\n", num[j]);
}
}
printf(
"END OF OUTPUT\n");
getchar();
return 0;
}

//判断一个数是否为完数(perfection)、abundant或deficient
int perfection(int n)
{
int j ;
int sum = 0;//因子之和
int flag;//记录返回值是什么完数(perfection)、abundant或deficient
int perfect = 0;
int abundant = 1;
int deficient = -1;

for (j = 2; j<n; j++)
{
if (n%j == 0)
{
sum
+= j;
}
}

if (sum == n)
{
flag
= perfect;
}
else if (sum >n)
{
flag
= abundant;
}
else if (sum <n)
{
flag
= deficient;
}
return flag;
}

posted @ 2011-04-03 22:46  涵曦  阅读(1354)  评论(0编辑  收藏  举报