From 6027dab47864727b3badb306bbd06e85d76e9025 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 12 Mar 2025 13:35:24 +0900 Subject: [PATCH] =?UTF-8?q?[20250312]=20BOJ=20/=20P4=20/=20=EC=9D=B4?= =?UTF-8?q?=ED=95=AD=20=EA=B3=84=EC=88=98=205=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...355\225\255 \352\263\204\354\210\230 5.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "khj20006/202503/12 BOJ P4 \354\235\264\355\225\255 \352\263\204\354\210\230 5.md" diff --git "a/khj20006/202503/12 BOJ P4 \354\235\264\355\225\255 \352\263\204\354\210\230 5.md" "b/khj20006/202503/12 BOJ P4 \354\235\264\355\225\255 \352\263\204\354\210\230 5.md" new file mode 100644 index 00000000..1305e7ff --- /dev/null +++ "b/khj20006/202503/12 BOJ P4 \354\235\264\355\225\255 \352\263\204\354\210\230 5.md" @@ -0,0 +1,72 @@ +```java + +import java.util.*; +import java.io.*; +import java.math.BigInteger; + + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static boolean[] sieve; + static long N, K, M; + static long[] cnt; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + nextLine(); + N = nextLong(); + K = nextLong(); + M = nextLong(); + + sieve = new boolean[(int)N+1]; + cnt = new long[(int)N+1]; + + } + + static void solve() throws Exception{ + + for(int i=2;i*i<=N;i++) if(!sieve[i]) for(int j=i*i;j<=N;j+=i) sieve[j] = true; + + for(int i=2;i<=N;i++) if(!sieve[i]) for(long k=i;k<=N;k*=i) cnt[i] += N/k; + for(int i=2;i<=N;i++) if(!sieve[i]) for(long k=i;k<=K;k*=i) cnt[i] -= K/k; + for(int i=2;i<=N;i++) if(!sieve[i]) for(long k=i;k<=N-K;k*=i) cnt[i] -= (N-K)/k; + + long ans = 1; + for(int i=2;i<=N;i++) ans = (ans * power(i, cnt[i])) % M; + bw.write(ans + "\n"); + + } + + static long power(long x, long y) { + if(y == 0) return 1; + if(y == 1) return x%M; + long h = power(x,y>>1) % M; + h = (h*h)%M; + if(y%2==0) return h; + return h*x%M; + } + +} + +```