题意:给你一个数,判断这个数是完美数,充裕数,不足数中的那一个。
注意:列表不会出现重复的整数;
代码实现:
import java.util.Scanner;
public class p1323 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[105];
int n = 0;
while (true) {
arr[n] = sc.nextInt();
if (arr[n] == 0) {
break;
}
n++;
}
System.out.println("PERFECTION OUTPUT");
int sum = 0;
String[] results = { "DEFICIENT", "PERFECT", "ABUNDANT" };
int ret = 1;
for (int i = 0; i < n; i++) {
sum = 1;
ret = 1;
/*
* 数据分析:
* 1)25=5*5
* 2)arr[i]的取值范围是1 < N < 100
*/
int k = arr[i];
for (int j = 2; j * j <= k; j++) {
if (k % j == 0) {
if (j * j == k) {
sum += j;
} else {
sum += j + k / j;
}
}
}
if (sum > k) {
ret++;
} else if (sum < k) {
ret--;
}
System.out.printf("%5d ", k);
System.out.println(results[ret]);
}
System.out.println("END OF OUTPUT");
}
}
Perfection
完美
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2138 Accepted Submission(s): 1290
Problem Description
From the article Number Theory in the 1994 Microsoft Encarta:
在1994年微软电子百科全书中发表了一篇算数理论文章。
"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.
如果a,b,c是一个整数,且a=bc,a是b的倍数,或者是b的倍数,那么b或者c被称之为除数或者a的一个因子。
If c is not 1/-1, b is called a proper divisor of a.
如果c不能整除a,那么b被称为a的因子。
Even integers, which include 0, are multiples of 2,
偶整数,包括0,和2的倍数,
for example, -4, 0, 2, 10;
例如-4, 0, 2, 10,这些数都是偶整数;
an odd integer is an integer that is not even,
奇整数就是不是偶整数的数。
for example, -5, 1, 3, 9.
例如-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.
举一个例子,6=1+2+3,28=1+2+4+7+14,他们都是完美数。
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;
例如9的因子有1,3,是没有两个3的,成为不足;
12, with proper divisors 1, 2, 3, 4, 6, is abundant."
例如12的因子为1,2,3,4,6,当然不包括自己,称为充裕。
Given a number, determine if it is perfect, abundant, or deficient.
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.
一个列表有n个正整数(每个数不大于6万),字符长度1 < N < 100。
A 0 will mark the end of the list.
0位列表结束标志。
Output
The first line of output should read PERFECTION OUTPUT.
输出的第一行应该输出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.
接下来输出N行,你应该判断列表中的整数,结果以下列格式显示。
Format counts: the echoed integers should be right justified within the first 5 spaces of the output line,
格式方面:结果应该右对齐,且是每一行的前5个空格。
followed by two blank spaces, followed by the description of the integer.
接下来有两个空格,然后是判断结果。
The final line of output should read END OF OUTPUT.
输出的最后一行应该输出END OF OUTPUT.
Sample Input
15 28 6 56 60000 22 496 0
Sample Output
PERFECTION OUTPUT 15 DEFICIENT 28 PERFECT 6 PERFECT 56 ABUNDANT 60000 ABUNDANT 22 DEFICIENT 496 PERFECT END OF OUTPUT
Source
Recommend