Skip to content

Commit 51ed6e1

Browse files
authored
[20251102] BOJ / G5 / 축구 / 이준희
1 parent edbff8c commit 51ed6e1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
double agoal = Double.parseDouble(br.readLine().trim()) / 100.0;
9+
double bgoal = Double.parseDouble(br.readLine().trim()) / 100.0;
10+
11+
boolean[] isPrime = new boolean[18+1];
12+
int[] primes = {2, 3, 5, 7, 11, 13, 17};
13+
for (int p : primes) isPrime[p] = true;
14+
15+
double nonPrimeA = 0.0;
16+
for (int a = 0; a <= 18; a++) {
17+
if (!isPrime[a]) {
18+
nonPrimeA += comb(18, a) * Math.pow(agoal, a) * Math.pow(1 - agoal, 18 - a);
19+
}
20+
}
21+
22+
double nonPrimeB = 0.0;
23+
for (int b = 0; b <= 18; b++) {
24+
if (!isPrime[b]) {
25+
nonPrimeB += comb(18, b) * Math.pow(bgoal, b) * Math.pow(1 - bgoal, 18 - b);
26+
}
27+
}
28+
29+
double no = nonPrimeA * nonPrimeB;
30+
31+
double result = 1.0 - no;
32+
33+
System.out.printf("%.6f\n", result);
34+
}
35+
36+
static double comb(int n, int k) {
37+
if (k > n) return 0;
38+
if (k > n - k) k = n - k;
39+
double res = 1.0;
40+
for (int i = 0; i < k; i++) {
41+
res *= (n - i);
42+
res /= (i + 1);
43+
}
44+
return res;
45+
}
46+
}
47+
```

0 commit comments

Comments
 (0)