import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
StringBuffer sb = new StringBuffer("");
sb.append("PERFECTION OUTPUT").append("\n");
while(true){
int x=s.nextInt();
if(x==0){
sb.append("END OF OUTPUT").append("\n");
break;
}
StringBuilder temp=new StringBuilder(x+"");
for(int i=temp.length();i<5;i++){
temp.insert(0, " ");
}
sb.append(temp).append(" ");
if(x==1){
sb.append("DEFICIENT").append("\n");
continue;
}
int dir=comp(x);
if(dir==1)
sb.append("DEFICIENT");
else if(dir==-1)
sb.append("ABUNDANT");
else
sb.append("PERFECT");
sb.append("\n");
}
System.out.print(sb);
}
static int comp(int x){
int sum=0;
for(int i=1;i<Math.sqrt(x);i++){
if(x%i==0){
sum+=i;
if(i!=1)
sum+=x/i;
}
}
if(is_Psquare(x))
sum+=Math.sqrt(x);
if(sum>x)
return -1;
if(sum<x)
return 1;
return 0;
}
static boolean is_Psquare(long x) {
long root = (long) (Math.floor(Math.sqrt(x) + 0.5));
return root * root == x;
}
}
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
StringBuffer sb = new StringBuffer("");
sb.append("PERFECTION OUTPUT").append("\n");
while(true){
int x=s.nextInt();
if(x==0){
sb.append("END OF OUTPUT").append("\n");
break;
}
StringBuilder temp=new StringBuilder(x+"");
for(int i=temp.length();i<5;i++){
temp.insert(0, " ");
}
sb.append(temp).append(" ");
if(x==1){
sb.append("DEFICIENT").append("\n");
continue;
}
int dir=comp(x);
if(dir==1)
sb.append("DEFICIENT");
else if(dir==-1)
sb.append("ABUNDANT");
else
sb.append("PERFECT");
sb.append("\n");
}
System.out.print(sb);
}
static int comp(int x){
int sum=0;
for(int i=1;i<Math.sqrt(x);i++){
if(x%i==0){
sum+=i;
if(i!=1)
sum+=x/i;
}
}
if(is_Psquare(x))
sum+=Math.sqrt(x);
if(sum>x)
return -1;
if(sum<x)
return 1;
return 0;
}
static boolean is_Psquare(long x) {
long root = (long) (Math.floor(Math.sqrt(x) + 0.5));
return root * root == x;
}
}
No comments:
Post a Comment