From 955281f7cbacf840a74013c0553f7d4b5d4d5aa2 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 22 Dec 2022 21:28:16 +0800 Subject: [PATCH] =?UTF-8?q?2186.=20[Sdoi2008]=E6=B2=99=E6=8B=89=E5=85=AC?= =?UTF-8?q?=E4=B8=BB=E7=9A=84=E5=9B=B0=E6=83=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/63a45b69cf75a716a1673402 --- BZOJ/2186/2186.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++ BZOJ/2186/data/1.in | 3 ++ BZOJ/2186/data/1.out | 3 ++ BZOJ/2186/data/2.in | 3 ++ BZOJ/2186/data/2.out | 3 ++ BZOJ/2186/data/3.in | 3 ++ BZOJ/2186/data/3.out | 3 ++ BZOJ/2186/data/4.in | 3 ++ BZOJ/2186/data/4.out | 3 ++ BZOJ/2186/data/5.in | 3 ++ BZOJ/2186/data/5.out | 3 ++ BZOJ/2186/data/6.in | 3 ++ BZOJ/2186/data/6.out | 3 ++ BZOJ/2186/data/7.in | 3 ++ BZOJ/2186/data/7.out | 3 ++ BZOJ/2186/data/8.in | 3 ++ BZOJ/2186/data/8.out | 3 ++ 17 files changed, 118 insertions(+) create mode 100644 BZOJ/2186/2186.cpp create mode 100644 BZOJ/2186/data/1.in create mode 100644 BZOJ/2186/data/1.out create mode 100644 BZOJ/2186/data/2.in create mode 100644 BZOJ/2186/data/2.out create mode 100644 BZOJ/2186/data/3.in create mode 100644 BZOJ/2186/data/3.out create mode 100644 BZOJ/2186/data/4.in create mode 100644 BZOJ/2186/data/4.out create mode 100644 BZOJ/2186/data/5.in create mode 100644 BZOJ/2186/data/5.out create mode 100644 BZOJ/2186/data/6.in create mode 100644 BZOJ/2186/data/6.out create mode 100644 BZOJ/2186/data/7.in create mode 100644 BZOJ/2186/data/7.out create mode 100644 BZOJ/2186/data/8.in create mode 100644 BZOJ/2186/data/8.out diff --git a/BZOJ/2186/2186.cpp b/BZOJ/2186/2186.cpp new file mode 100644 index 00000000..1d21083e --- /dev/null +++ b/BZOJ/2186/2186.cpp @@ -0,0 +1,70 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e7 + 5; + +int t, mod, p, primes[N], fac[N], fac_phi[N]; +bool not_prime[N]; + +int binpow(int a, int b) { + int res = 1; + + while (b) { + if (b & 1) res = static_cast(res) * a % mod; + a = static_cast(a) * a % mod; + b >>= 1; + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> t >> mod; + + for (int i = 2; i < N; i++) { + if (!not_prime[i]) primes[++p] = i; + + for (int j = 1; j <= p && i * primes[j] < N; j++) { + not_prime[i * primes[j]] = true; + + if (i % primes[j] == 0) break; + } + } + + fac[0] = 1; + + for (int i = 1; i < N; i++) { + if (i % mod) { + fac[i] = static_cast(fac[i - 1]) * i % mod; + } else { + fac[i] = fac[i - 1]; + } + } + + fac_phi[1] = 1; + + for (int i = 2; i < N; i++) { + if (not_prime[i]) { + fac_phi[i] = static_cast(fac_phi[i - 1]) * i % mod; + } else { + fac_phi[i] = static_cast(fac_phi[i - 1]) * (i - 1) % mod; + } + } + + while (t--) { + int n, m; + + cin >> n >> m; + + cout << (n / mod > m / mod ? 0 : static_cast(fac[n]) * fac_phi[m] % mod * binpow(fac[m], mod - 2) % mod) << endl; + } + + return 0; +} diff --git a/BZOJ/2186/data/1.in b/BZOJ/2186/data/1.in new file mode 100644 index 00000000..f5e903fe --- /dev/null +++ b/BZOJ/2186/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e175c286a90ddda62c9b41af7108ccb738bf370a0ff83e0ece72c12198860e2 +size 22911 diff --git a/BZOJ/2186/data/1.out b/BZOJ/2186/data/1.out new file mode 100644 index 00000000..0e3256f0 --- /dev/null +++ b/BZOJ/2186/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c156b9891acb989d3d3fccd2413c0ae18b4932929e749a79b6bc8a425d06871 +size 13830 diff --git a/BZOJ/2186/data/2.in b/BZOJ/2186/data/2.in new file mode 100644 index 00000000..a9be7436 --- /dev/null +++ b/BZOJ/2186/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e51068f56e43bdb51f987f1fafa379be549dc9acfdd858bd2d77f4cb68e9e8b +size 134685 diff --git a/BZOJ/2186/data/2.out b/BZOJ/2186/data/2.out new file mode 100644 index 00000000..63def87c --- /dev/null +++ b/BZOJ/2186/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ab421ed8335de083eec3a8badbf884be3058f34b188d2772216e2bf951f2818 +size 77678 diff --git a/BZOJ/2186/data/3.in b/BZOJ/2186/data/3.in new file mode 100644 index 00000000..29ac10c5 --- /dev/null +++ b/BZOJ/2186/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e739335368dfb12da0be364566b209db1fe8a2adc06244cfd32b2da508c8aea +size 132234 diff --git a/BZOJ/2186/data/3.out b/BZOJ/2186/data/3.out new file mode 100644 index 00000000..a863f022 --- /dev/null +++ b/BZOJ/2186/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d430316045da5a801ace2a8db305754c3da4224afaae554a36a33de848318c3 +size 72139 diff --git a/BZOJ/2186/data/4.in b/BZOJ/2186/data/4.in new file mode 100644 index 00000000..3d28fc24 --- /dev/null +++ b/BZOJ/2186/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:adec7f177f12e03bd9e30a4104ffc008b7a42ba27f6c6542a56806e807114184 +size 154812 diff --git a/BZOJ/2186/data/4.out b/BZOJ/2186/data/4.out new file mode 100644 index 00000000..5369e3f1 --- /dev/null +++ b/BZOJ/2186/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e0f7d6191ff06bf093687bb444451e882ae39a5b6167c57cc89360984fb6fa2 +size 88887 diff --git a/BZOJ/2186/data/5.in b/BZOJ/2186/data/5.in new file mode 100644 index 00000000..4f7153a3 --- /dev/null +++ b/BZOJ/2186/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3477635ac64456fe7863094a2259ce7a71366c6770ea874c1e121a0828343b2 +size 26 diff --git a/BZOJ/2186/data/5.out b/BZOJ/2186/data/5.out new file mode 100644 index 00000000..709258f4 --- /dev/null +++ b/BZOJ/2186/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ea6613bc44419807ac44021f8903db88ea2d85426b68980b81c50424cc025f4 +size 9 diff --git a/BZOJ/2186/data/6.in b/BZOJ/2186/data/6.in new file mode 100644 index 00000000..917716cc --- /dev/null +++ b/BZOJ/2186/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c87f4a0b87aff3d92a9adb5c70d985dd42706a25b3432ad9b37701549fa45f4 +size 1368 diff --git a/BZOJ/2186/data/6.out b/BZOJ/2186/data/6.out new file mode 100644 index 00000000..62697451 --- /dev/null +++ b/BZOJ/2186/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84429ad2a4ffba5364cefdbf2cbf01c73c51d5c61b5f4482c19c1bc9868b9a4d +size 886 diff --git a/BZOJ/2186/data/7.in b/BZOJ/2186/data/7.in new file mode 100644 index 00000000..9b165119 --- /dev/null +++ b/BZOJ/2186/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce3d7ad39366fc0875b8a95db555922aba1c3513f4346e77f324158ca72f6ce7 +size 154497 diff --git a/BZOJ/2186/data/7.out b/BZOJ/2186/data/7.out new file mode 100644 index 00000000..ade5275d --- /dev/null +++ b/BZOJ/2186/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76a858c972f7306fd2523f5cc1da3b243cba813e1261a056312c7233f09ca656 +size 78803 diff --git a/BZOJ/2186/data/8.in b/BZOJ/2186/data/8.in new file mode 100644 index 00000000..54cc739e --- /dev/null +++ b/BZOJ/2186/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3330d56c1ad008be22c5a68490ede3c3dd23a2bf1e53652252079f44d7c3e8e +size 27 diff --git a/BZOJ/2186/data/8.out b/BZOJ/2186/data/8.out new file mode 100644 index 00000000..760b5b7d --- /dev/null +++ b/BZOJ/2186/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a75304b129cf3cafd3533275b6a08c254e797bef8163e0c15180aa8a5c68f83 +size 17