Perfect Numbers
According to mathematics "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, 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 equal 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers.
Even perfect numbers (except 6) give remainder 1 when divided by 9.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." Problem Statement: Given a number, determine if it is perfect, abundant, or deficient.
First four perfect numbers were the only ones known to early Greek mathematics, and the mathematician Nicomachus had noted 8,128 as early as 100 AD. Then, in 1456, an unknown mathematician recorded the earliest reference to a fifth perfect number, with 33,550,336 being correctly identified for the first time. In 1588, the Italian mathematician Pietro Cataldi identified the sixth (8,589,869,056) and the seventh (137,438,691,328) perfect numbers.
Input
A positive integer N ; 1 <= N <= 60000.
Output
Output should list input integer whether it is perfect, deficient, or abundant, as shown in the examples below.
Sample Input Output
15 DEFICIENT
28 PERFECT
56 ABUNDANT
ANSWER
import java.util.Scanner;
public class QG {
public static void main(String[]args){
int perfect[]={6,28,496,8128};
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
int inp=Integer.parseInt(input);
String out=null;
for (int i = 0; i < perfect.length; i++) {
if(inp==perfect[i]){
out="PERFECT";
break;
}
}
if(out==null){
int sum=0;
for (int i = 1; i < inp; i++) {
int x=inp%i;
if(x==0){
sum+=i;
}
}
if(sum<inp)
out="DEFICIENT";
else
out="ABUNDANT";
}
out=out.trim();
System.out.print(out);
}
}
0 comments:
Post a Comment