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;
}
}