From 51ed6e19bb71e2d43434cef5c2d870ad05418bfc Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sun, 2 Nov 2025 22:47:53 +0900 Subject: [PATCH] =?UTF-8?q?[20251102]=20BOJ=20/=20G5=20/=20=EC=B6=95?= =?UTF-8?q?=EA=B5=AC=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../02 BOJ G5 \354\266\225\352\265\254.md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "JHLEE325/202511/02 BOJ G5 \354\266\225\352\265\254.md" diff --git "a/JHLEE325/202511/02 BOJ G5 \354\266\225\352\265\254.md" "b/JHLEE325/202511/02 BOJ G5 \354\266\225\352\265\254.md" new file mode 100644 index 00000000..564f733b --- /dev/null +++ "b/JHLEE325/202511/02 BOJ G5 \354\266\225\352\265\254.md" @@ -0,0 +1,47 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + double agoal = Double.parseDouble(br.readLine().trim()) / 100.0; + double bgoal = Double.parseDouble(br.readLine().trim()) / 100.0; + + boolean[] isPrime = new boolean[18+1]; + int[] primes = {2, 3, 5, 7, 11, 13, 17}; + for (int p : primes) isPrime[p] = true; + + double nonPrimeA = 0.0; + for (int a = 0; a <= 18; a++) { + if (!isPrime[a]) { + nonPrimeA += comb(18, a) * Math.pow(agoal, a) * Math.pow(1 - agoal, 18 - a); + } + } + + double nonPrimeB = 0.0; + for (int b = 0; b <= 18; b++) { + if (!isPrime[b]) { + nonPrimeB += comb(18, b) * Math.pow(bgoal, b) * Math.pow(1 - bgoal, 18 - b); + } + } + + double no = nonPrimeA * nonPrimeB; + + double result = 1.0 - no; + + System.out.printf("%.6f\n", result); + } + + static double comb(int n, int k) { + if (k > n) return 0; + if (k > n - k) k = n - k; + double res = 1.0; + for (int i = 0; i < k; i++) { + res *= (n - i); + res /= (i + 1); + } + return res; + } +} +```