1.

/**
* Angewandte Mathematik, SS11
* Problem: 382 - Perfection
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=318
*
* @author Unverzart Michael
* @author Wurth Manuel
* @version 1.0, 23/3/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.136
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws Exception{

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

String inputLine;

System.out.println("PERFECTION OUTPUT");

while((inputLine = reader.readLine()) != null){

StringTokenizer st = new StringTokenizer(inputLine);

int zahl = 0;

while(st.hasMoreTokens()){

zahl = new Integer(st.nextToken());

if(zahl==0) break;

int perfection = 0;

for(int i = 1;i<=(zahl/2);i++) if((zahl%i)==0) perfection+=i;

System.out.format("%5d %s%n",zahl,perfection<zahl?"DEFICIENT":perfection>zahl?"ABUNDANT":"PERFECT");

}

if(zahl==0) break;

}

System.out.println("END OF OUTPUT");
}
}

2.

import java.util.Scanner;

/**
* Angewandte Mathematik, SS11
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/external/3/382.pdf
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 03/24/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.152
*/
public class Main
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

int number = -1;
System.out.println("PERFECTION OUTPUT");

int sum = 0;
String solution = "";
String space = "";
while((number= sc.nextInt())!=0)
{
// calculate sum
for(int j = 1; j<= number/2; j++)
{
if(number%j==0)
{
sum += j;
}
}

if(sum > number)
{
solution = "ABUNDANT";
}
else if(sum < number)
{
solution = "DEFICIENT";
}
else
{
solution = "PERFECT";
}


// print solution
for (int j=0; j<5-(number+"").length(); j++)
{
space += " ";
}

System.out.println(space+number+" "+solution);
space = "";
sum=0;
}

System.out.println("END OF OUTPUT");
}

}

3.

/**
* Angewandte Mathematik, SS11
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/external/3/382.html
*
* @author Markus Schöllner
* @author Andreas Maier
* @version 1.0, 03/27/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.172
*/

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number;
int result;
System.out.println("PERFECTION OUTPUT");
do {
number = scanner.nextInt();
result = 0;
if(number != 0 && number <= 60000) {
for(int c = 1; c < number; c++) {
if(number%c == 0) result = result + c;
}
System.out.printf("%5d",number);
if(result==number) System.out.println(" PERFECT");
else {
if(result < number) System.out.println(" DEFICIENT");
else System.out.println(" ABUNDANT");
}
}

}while(number != 0);
System.out.println("END OF OUTPUT");
}
}

4.


/**
* Angewandte Mathematik, SS11
* Problem: 382 Perfection
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=2113
*
* @author Schramm, Felix
* @author Vogel, Johannes
* @version 1.0, 03/28/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.124
*/

import java.util.*;

public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.print("PERFECTION OUTPUT\n");
while (scanner.hasNextInt()) {
printPerfection(scanner.nextInt());
}
System.out.println("END OF OUTPUT");
}

private static void printPerfection(int zahl){
if(zahl!=0){
int sumFactors = 0;
int third = zahl/3;
for(int i=1;i<=third;i++)
sumFactors+=zahl%i==0?i:0;
if(zahl%zahl/2==0)
sumFactors+=zahl/2;

System.out.printf("%5d ",zahl);
if(sumFactors-zahl<0)
System.out.print("DEFICIENT\n");
else if(sumFactors-zahl==0)
System.out.print("PERFECT\n");
else
System.out.print("ABUNDANT\n");
}
}


}

5.

package sem2.am.perfection;

/**
* Angewandte Mathematik, SS11
* Problem: 382 - Perfection
* Link: http://uva.onlinejudge.org/external/3/382.pdf
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 03/28/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.120
*/

import java.util.*;

class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean first = false;

while (scanner.hasNext()) {

boolean spaces = false;
if (!first) {
System.out.println("PERFECTION OUTPUT");
first = true;
}

int sum = 0;
int aktzahl = scanner.nextInt();

if (aktzahl == 0) {
break;
}

for (int i = 1; i < aktzahl; i++) {
if ((aktzahl % i) == 0) {
sum = sum + i;
}
}

if (aktzahl <= 60000) {

if (aktzahl < 10 && aktzahl > 0 && !spaces) {
System.out.print(" ");
spaces = true;
}
if (aktzahl >= 10 && aktzahl < 100 && !spaces) {
System.out.print(" ");
spaces = true;
}
if (aktzahl >= 100 && aktzahl < 1000 && !spaces) {
System.out.print(" ");
spaces = true;
}
if (aktzahl >= 1000 && aktzahl < 10000 && !spaces) {
System.out.print(" ");
spaces = true;
}
if (aktzahl >= 10000 && !spaces) {
System.out.print("");
spaces = true;
}
if (sum == aktzahl) {
System.out.print(aktzahl + " PERFECT\n");
}

if (sum > aktzahl) {
System.out.print(aktzahl + " ABUNDANT\n");
}

if (sum < aktzahl) {
System.out.print(aktzahl + " DEFICIENT\n");
}
}

}
System.out.println("END OF OUTPUT");
}
}

6.

/**
* Angewandte Mathematik, SS11
* PProblem: 382 - Perfection
* Link: http://uva.onlinejudge.org/external/3/382.pdf
* @author Ritter Marius
* @author Wende Tom
* @author Zehentbauer Stefan
* @version 1.0, 03/29/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.132
*/

import java.util.Scanner;

public class Main {

public static void main(String[] args){
Scanner bsr = new Scanner(System.in);
int zahl = 1;
System.out.println("PERFECTION OUTPUT");
do{

int n = 0;
zahl = bsr.nextInt();

for(int i = 1; i < zahl; i++)
{
if(zahl%i == 0)
n = n + i;
}
if(zahl != 0){
if(n == zahl){
System.out.printf("%5d PERFECT\n", zahl);
}else if(n < zahl){
System.out.printf("%5d DEFICIENT\n", zahl);
}else System.out.printf("%5d ABUNDANT\n", zahl);
}
}while(zahl!=0);

System.out.println("END OF OUTPUT");
}
}


7.

/**
* Angewandte Mathematik, SS11
* Problem: 10104 - Euclid Problem
* http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1045
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-04-02 09:03:1
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.148
*/

import java.util.*;
public class Main
{
// erweiterter Euklidischer Algorithmus, rekursiv implementiert, gibt, wenn fertig:
// in result[0]: GCD, result[1]: x, result[2]: y, so dass: Ax + By = GCD!
// man muss Datentyp long nehmen, da sonst die für int zu verfügung stehende stellenanzahl
// für die multiplikation nicht mehr ausreicht
static long[] extendedEuklid(long A, long B)
{
if (B == 0)
return new long[] { A, 1, 0 };
long[] result = extendedEuklid(B, A % B);
long d = result[0];
long a = result[2];
long b = result[1] - (A / B) * result[2];
return new long[] { d, a, b };
}

public static void main(String[] args)
{

/* StringBuilder sb = new StringBuilder("");
for(int i=1; i<=1000; i++)
{
sb = sb.append(i+" "+(1000-i)+"\n");
}
String s = sb.toString();
*/
Scanner scanner = new Scanner(System.in);
while(true)
{
try
{
int A = scanner.nextInt();
int B = scanner.nextInt();
long[] result = extendedEuklid(A, B);
// System.out.println(A+" "+B);
System.out.println(result[1]+" "+result[2]+" "+result[0]);
}
catch(NoSuchElementException nsee)
{
break;
}
}
}

}

8.

/**
* Angewandte Mathematik, SS11
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=318
*
* @author Marco Wolff
* @author Christian Weber
* @author Christoph Waldleitner
* @version 1.0, 10/23/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.116
*/

import java.io.*;
import java.util.StringTokenizer;

public class Main
{
public static void main(String[] args)
{
int a=0;
BufferedReader give = getStr();
int b=0;

while (true)
{
String in = "0";
try{
in = give.readLine();
}
catch (IOException e){}
StringTokenizer tk = new StringTokenizer(in);
if(b==0)
{
System.out.println("PERFECTION OUTPUT");
b++;
}
while (tk.hasMoreTokens())
{
a = Integer.parseInt(tk.nextToken());
if (a == 0)
{
System.out.println("END OF OUTPUT");
System.exit(0);
}
int sum = 1;
String out = "";
for (int i = 2; i <= a/2; i++)
{
if (a % i == 0)
{
sum += i;
}
}
for (int i = 5; i != (String.valueOf(a).length()); i--)
{
out += " ";
}
if (sum == a&&a!=1)
{
System.out.println(out + a + " PERFECT");
} else if (sum < a||a==1)
{
System.out.println(out + a + " DEFICIENT");
} else
{
System.out.println(out + a + " ABUNDANT");
}
}
}
}

public static BufferedReader getStr()
{
BufferedReader br;
br = new BufferedReader(new InputStreamReader(
System.in));
return br;
}
}



----------------------------------------------------------

1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=318
*
* @author Fabian Liebl
* @version 1.0, 10/06/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.328
*/

import java.io.*;
import java.util.*;

public class Main {

public static void main(String[] args) throws IOException {
//BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);

int number;
//String[] numbers;
Vector<Integer> properDivisors = new Vector<Integer>();
int addedProperDivisors;

System.out.println("PERFECTION OUTPUT");

//numbers = inputReader.readLine().split(" ");

//for (int n = 0; n < numbers.length; n++) {
while (true) {
//number = Integer.parseInt(numbers[n]);
number = sc.nextInt();

if (number == 0) {
System.out.println("END OF OUTPUT");
return;
}

// Get all proper divisors
properDivisors.clear();
for (int i = 1; i < number; i++) {
for (int j = number; j > 1; j--) {
if (i*j == number) {
properDivisors.add(i);
break;
}
}
}

// Add all proper divisors
addedProperDivisors = 0;
for(Integer i: properDivisors) {
addedProperDivisors += i;
}

if (addedProperDivisors == number) {
System.out.printf("%5d PERFECT\n", number);
} else {
if (addedProperDivisors < number) {
System.out.printf("%5d DEFICIENT\n", number);
} else {
System.out.printf("%5d ABUNDANT\n", number);
}
}
}
}

}


2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=318
*
* @author Manuel Hager
* @version 1.1, 10/21/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.116
*/

import java.util.Scanner;

public class Main
{
private static StringBuilder outputString = new StringBuilder("PERFECTION OUTPUT\n");

private static void add(int number) {
int sum = calcDivisorSum(number);
String result = "PERFECT";

if(sum != number) {
result = sum > number? "ABUNDANT" : "DEFICIENT";
}

outputString.append(String.format("%5d %s%n", number, result));
}

private static int calcDivisorSum(int value) {
int sum = 1;

int sqrt = (int)Math.sqrt(value);

for(int i = 2; i <= sqrt; i++) {
if(value % i == 0) {
sum += i;
sum += (value / i);
}
}

return sqrt * sqrt == value? sum - sqrt : sum ;
}

private static void print() {
outputString.append("END OF OUTPUT");
System.out.println(outputString.toString());
}

public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);

for(int number = scanner.nextInt(); number != 0; number = scanner.nextInt()) {
add(number);
}
print();

scanner.close();
}
}



3.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/external/3/382.pdf
*
* @author Robert Reichart
* @version 1.0, 19/03/2010
*
* Status : Accepted
* Runtime: 0.104
*/

import java.io.*;
import java.util.*;

class Main {
//Main Methode
public static void main(String[] args){
//Einlesen der Werte aus der Eingabe
Scanner in = new Scanner(System.in);
//erstellen einer Ausgabe
PrintWriter out = new PrintWriter(System.out);
//Array fuer Maximale anzahl an werten
Integer[] werte = new Integer[100];
//uebertragen der werte aus dem Scanner in den Array
for(int i = 0; in.hasNext(); i++){
werte[i] = in.nextInt();
}

//Ausgabe des Einleitungs Outputs
out.println("PERFECTION OUTPUT");
//Testen jedes Wertes und ausgabe des entsprechenden Ergebnisses
for(int i = 0; i < werte.length && werte[i] != 0; i++){
int sum = divsum(werte[i]);
if(sum == werte[i]){
out.printf("%5d PERFECT%n", werte[i]);
}else if(sum < werte[i]){
out.printf("%5d DEFICIENT%n", werte[i]);
} else {
out.printf("%5d ABUNDANT%n", werte[i]);
}
}
//Ausgabe des End outputs
out.println("END OF OUTPUT");
out.close();

}

//Methode um die Summe aller Teiler einer Zahl zu berechnen
static int divsum(int zahl){
//berechnung aller Teiler von n und bilden deren sSumme
int sum = 0;
int n = zahl/2;
//schleife um alle in frage kommenden werte durchzutesten
for(int i = 1; i <= n; i++){
//wenn i ein teiler von n ist zu sum hinzuaddieren und ausgeben
if(zahl%i == 0){
sum += i;
}
}
return sum;
}
}

4.


 

/**

* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10

* Problem: 382 Perfection

* Link: http://uva.onlinejudge.org/external/3/382.pdf

*

* @author Viktoriya Ryabova

* @version 1.0, 04/21/2010

*

* Method : Ad-Hoc

* Status : accepted

* Runtime: 0.144

*/

 

import java.util.Scanner;

public class Main {

/**

* @param args

*/

public static void main(String[] args) {

Scanner sc = new Scanner (System.in);

int eingabe []= new int[100];

//werte in array einlesen

for(int i=0; sc.hasNext(); i++){

eingabe[i] = sc.nextInt();

if(i==0) System.out.println("PERFECTION OUTPUT");

if (eingabe[i]!=0){

//vergleichen die summe mit dem wert selbst

if(eingabe[i]==countSum(eingabe[i]))System.out.println((printFormat(eingabe[i]))+ eingabe[i] +" PERFECT");

else if (eingabe[i]>countSum(eingabe[i]))System.out.println((printFormat(eingabe[i]))+ eingabe[i] +" DEFICIENT");

else System.out.println((printFormat(eingabe[i]))+ eingabe[i] +" ABUNDANT");

}

else {

System.out.println("END OF OUTPUT");

}

}

}

 

private static int countSum (int number){

int sum=0;

for (int i=1; i<=number/2;i++){

if(number%i==0){

sum+=i;

}

}

return sum;

}

public static String printFormat(int number){

String spaceCount = String.valueOf(number);

String str="";

for (int i=1; i<6-spaceCount.length(); i++){

str += " ";

}

return str;

}

}


5.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 382 Perfection
* Link: http://uva.onlinejudge.org/external/3/382.pdf
*
* @author M. Lambeck / M. Haus
* @version 1.0, 10/06/2010
*
* Status : Accepted
* Runtime:
*/

import java.util.Scanner;

public class Main
{
static int next = 0;
static boolean intro = true;


public static void main (String[] args)
{
Scanner st = new Scanner(System.in);


while(true)
{
int num = st.nextInt();

if (num == 0)
break;

doit(num);
}


System.out.println("END OF OUTPUT");
}


private static void doit(int num)
{

if (intro)
{
System.out.println("PERFECTION OUTPUT");
intro = false;
}


if (num == 1)
{
System.out.printf("%5d  DEFICIENT%n",num);
return;
}


int tmp = (int) (Math.sqrt(num) + 0.001);
int sum = 1;


while (tmp > 1)
{


if (num % tmp == 0)
{
sum += tmp;
sum += (num / tmp);


}
tmp--;
}



if (sum >= num)
{
if (sum == num)
{
System.out.printf("%5d  PERFECT%n", num);


} else
{
System.out.printf("%5d  ABUNDANT%n",num);
}
} else
{
System.out.printf("%5d  DEFICIENT%n",num);
}


}
}