forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa00412_Pi.java
46 lines (38 loc) · 1.05 KB
/
UVa00412_Pi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 353 (412 - Pi) */
/* SUBMISSION: 09121599 */
/* SUBMISSION TIME: 2011-08-06 20:24:10 */
/* LANGUAGE: 2 */
import java.util.*;
import java.io.*;
public class UVa00412_Pi {
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
int N = Integer.parseInt(in.readLine());
if (N == 0)
break;
int[] numbers = new int[N];
for (int i = 0; i < N; ++i)
numbers[i] = Integer.parseInt(in.readLine());
int cnt = 0;
int total = 0;
for (int i = 0; i < N; ++i)
for (int j = i + 1; j < N; ++j) {
++total;
if (gcd(numbers[i], numbers[j]) == 1)
++cnt;
}
if (cnt == 0)
System.out.println("No estimate for this data set.");
else
System.out.printf(Locale.ENGLISH, "%.6f%n", Math.sqrt((double)total * 6.0 / cnt));
}
in.close();
System.exit(0);
}
}