From 618ebab5a0fafc9a01dbfae54ae83cdf844588f9 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 6 Mar 2025 22:27:33 +0900 Subject: [PATCH] =?UTF-8?q?[20250306]=20BOJ=20/=20P3=20/=20N!!!...!=20mod?= =?UTF-8?q?=20P=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202503/06 BOJ P3 N!!!...! mod P.md | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 khj20006/202503/06 BOJ P3 N!!!...! mod P.md diff --git a/khj20006/202503/06 BOJ P3 N!!!...! mod P.md b/khj20006/202503/06 BOJ P3 N!!!...! mod P.md new file mode 100644 index 00000000..4c9fbdf1 --- /dev/null +++ b/khj20006/202503/06 BOJ P3 N!!!...! mod P.md @@ -0,0 +1,53 @@ +```java + +#include +using namespace std; +using ll = long long; + +ll N, K, P; + +ll power(ll n, ll m){ + if(m == 0) return 1; + if(m == 1) return n; + ll p = power(n,m>>1); + if(m&1) return p*p%P*n%P; + return p*p%P; +} + +int main() { + cin.tie(0)->sync_with_stdio(0); + + cin >> N >> K >> P; + + if (N == 2) return cout << (P == 2 ? 0 : 2), 0; + + if (K >= 4) return cout << 0, 0; + + if (K == 2) { + if (N >= 13) return cout << 0, 0; + ll fac = 1; + for (int i = 1; i <= N; i++) fac *= i; + if (fac >= P) return cout << 0, 0; + if(N <= 11){ + ll ans = 1; + for(int i=2;i<=fac;i++) ans = (ans * i) % P; + return cout<= 4) return cout << 0, 0; + ll ans = 1; + for (int i = 1; i <= 720; i++) ans = (ans * i) % P; + cout << ans; + } + +} + +```