1.

/**
* Angewandte Mathematik, SS11
* Problem: 412 PI
* Link: http://uva.onlinejudge.org/external/4/412.pdf
*
* @author Ritter Marius
* @author Wende Tom
* @author Zehentbauer Stefan
* @version 1.0, 03/30/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.712
*/

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

public static double G(double a, double b)
{
while(a != b) if(a > b) a -= b; else b -= a;
return(a);
}
public static void main(String[] args)
{
double ggt = 1.00;
Scanner bsr = new Scanner(System.in);
ArrayList<Double> eingabe = new ArrayList<Double>();
int count = 1;

while(count != 0)
{
double counter = 0;
eingabe.clear();
count = bsr.nextInt();
for(int i = 0; i < count; i++)
{
eingabe.add(bsr.nextDouble());
}

for(int i = 0; i < eingabe.size()-1; i++)
{
double zahl1 = eingabe.get(i);

for(int k = i+1; k < eingabe.size(); k++)
{
double zahl2 = eingabe.get(k);
ggt = Main.G(zahl2,zahl1);
if(ggt == 1)
counter++;
}
}
if (counter == 0 && count != 0)
{
System.out.println("No estimate for this data set.");
}
else if(counter != 0 && count != 0)
{
double y = (eingabe.size()*(eingabe.size()-1))/2.00;
double x = counter;
double ergebnis = Math.sqrt(6.0*y/x);
String out = String.format("%.6f\n", ergebnis);
System.out.printf("%s",out.replace(",", "."));
}
}
}
}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 412 - Pi
* http://uva.onlinejudge.org/external/4/412.pdf
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-03-28 09:10:48
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.232
*/

import java.util.*;

public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
for(int n = scanner.nextInt(); n != 0; n = scanner.nextInt())
{
int[] numbers = new int[n];
int numberOfGgT1Pairs = 0;
int numberOfPairs = 0;
for(int i = 0; i < n; i++)
{
numbers[i] = scanner.nextInt();
}
for(int i = 0; i < (n-1); i++ )
{
int temp = numbers[i];
for(int j = i+1; j < n; j++)
{
int zahl1 = temp;
int zahl2 = numbers[j];
//Euklidischer algorithmus
while(zahl1 != 0 && zahl2 != 0)
{
if(zahl1 > zahl2)
{
zahl1 = zahl1 - zahl2;
}
else
{
zahl2 = zahl2 - zahl1;
}
}
int ggT = zahl1 == 0? zahl2: zahl1;
if(ggT == 1)
numberOfGgT1Pairs++;
numberOfPairs++;
}
}
if(numberOfGgT1Pairs == 0)
{
System.out.println("No estimate for this data set.");
}
else
{
double pi = Math.sqrt(((double)numberOfPairs/numberOfGgT1Pairs)*6);
System.out.printf("%.6f\n", pi);
}
}
}
}


3.

/**
* Angewandte Mathematik, SS11
* Problem: 412 Pi
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=353
*
* @author Peter Weismann
* @author Pirmin Schneider
* @version 1.0, 03/31/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.708
*/


import java.util.Scanner;
public class Main {


public static void main(String[] args) {


Scanner input = new Scanner(System.in);

// Coprime ist die Anzahl der Paare mit ggT = 1. approx ist die Annäherung an Pi.
int [] values;;
int coprime = 0;
double approx = 0;
int allCouples = 0;

// for-Schleife liest einmal die numberOfElements ein und setzt jedes Mal erneut die Zählvariablen auf 0
for (int numberOfElements = input.nextInt(); numberOfElements != 0; coprime = 0, allCouples = 0) {

values = new int[numberOfElements];

// Einlesen der Werte
for (int i = 0; i < numberOfElements; i++) {
values[i] = input.nextInt();
}


// Schleife, die die Anzahl der Paare zaehlt und auf ggT = 1 ueberprueft.
for (int i = 0; i < numberOfElements; i++) {
for (int k = i; k < numberOfElements; k++) {

if (i != k) {
allCouples++;

if (ggT(values[i], values[k])) {
coprime++;
}
}
}
}

// Fallunterscheidung, um zu bestimmen, ob es eine Annäherung gibt
if (coprime != 0) {
approx = Math.sqrt((double)allCouples/coprime*6);
System.out.printf("%6f%n", approx);
}
else
System.out.println("No estimate for this data set.");

numberOfElements = input.nextInt();


}

}

// Zusaetzliche Methode prüft, ob ggT = 1 ist
public static boolean ggT(int a, int b) {
while (a != b) {
if (a>b)
a = a-b;
else
b = b-a;
}
return a == 1 ? true : false;

}

}


4.

/**
* Angewandte Mathematik, SS11
* Problem: 412 Pi
* Link: http://uva.onlinejudge.org/external/4/412.pdf
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 03/29/2011
*
* Method : Ad-hoc
* Status : Accepted
* Runtime: 1.328
*/

import java.util.Scanner;


public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number;
double result;

while((number = sc.nextInt()) != 0)
{
int maxPairs = (number*(number-1))/2;
int fitPairs = 0;
int[] numbers = new int[number];
for(int i = 0; i < number; i++)
{
numbers[i] = sc.nextInt();
}

for(int i = 0; i< numbers.length; i++)
{
for(int j = i+1; j < numbers.length; j++)
{
if(ggT(numbers[i], numbers[j]) == 1)
{
fitPairs++;
}
}
}

if(fitPairs==0)
{
System.out.println("No estimate for this data set.");
}
else
{
result = Math.sqrt((double)(6*maxPairs)/fitPairs);
System.out.printf("%f\n", result);
}
}
}

// Euklid Algo
public static int ggT(int a, int b)
{
int r = -1;

while(r!=0)
{
r = a%b;
a = b;
b = r;
}

return a;
}
}


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

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

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

public class Main {

// Rekursive Euklid algorithm
private static int ggT(int a, int b) {
if (a < b) return ggT(b, a);
if ((a == b) || (b == 0)) return a;
return ggT(b, a%b);
}

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

int numberOfValues;
int[] values;
int numberOfPairs;
int numberOfCommonFactors;
int commonFactor;
double pi;

numberOfValues = sc.nextInt();
while (numberOfValues != 0) {
// Read values
values = new int[numberOfValues];
for (int i = 0; i < numberOfValues; i++) {
values[i] = sc.nextInt();
}

// Check pairs
numberOfPairs = 0;
numberOfCommonFactors = 0;

for (int firstNumber = 0; firstNumber < numberOfValues-1; firstNumber ++) {
for (int secondNumber = firstNumber + 1; secondNumber < numberOfValues; secondNumber ++) {
// Pair (firstNumber, secondNumber)
numberOfPairs ++;
if (ggT(values[firstNumber], values[secondNumber]) > 1) {
numberOfCommonFactors ++;
}
}
}

if (numberOfCommonFactors == numberOfPairs) {
System.out.println("No estimate for this data set.");
} else {
pi = Math.sqrt((6.0 * numberOfPairs) / (numberOfPairs - numberOfCommonFactors));
System.out.printf("%.6f\n", pi);
}

numberOfValues = sc.nextInt();
}

}

}

2.

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

import java.io.IOException;
import java.util.Scanner;

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

while(true)
{
int n = scanner.nextInt();

if(n == 0) {
break;
}

int[] numbers = new int[n];

for(int i = 0; i < n; i++) {
numbers[i] = scanner.nextInt();
}

printOut(numbers);
}

scanner.close();
}

private static void printOut(int[] values) {
int pairCount = 0;
int noCommonFactorCount = 0;

for(int first = 0; first < values.length - 1; first++) {
for(int second = first + 1; second < values.length; second++) {
pairCount++;
if(ggT(values[first], values[second]) == 1) {
noCommonFactorCount++;
}
}
}

if(noCommonFactorCount == 0) {
System.out.println("No estimate for this data set.");
}
else {
double pi = Math.sqrt((6.0 * pairCount) / noCommonFactorCount);
System.out.printf("%.6f%n", pi);
}
}

private static int ggT(int a, int b){
int r;
do
{
r = (a%b);
a = b;
b = r;
}while(b!=0);

return a;
}
}