From a9dacf2e67ce44c3bf242c7befd70a5620afabfa Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 20 Feb 2023 12:06:32 +0800 Subject: [PATCH] =?UTF-8?q?#631.=20=E6=95=85=E4=BA=8B=E4=B9=A6=EF=BC=88sto?= =?UTF-8?q?ry=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/71133 --- S2OJ/631/631.cpp | 63 ++++++++++++++++++++++++++++++++++++++ S2OJ/631/data/problem.conf | 3 ++ S2OJ/631/data/story1.in | 3 ++ S2OJ/631/data/story1.out | 3 ++ S2OJ/631/data/story10.in | 3 ++ S2OJ/631/data/story10.out | 3 ++ S2OJ/631/data/story2.in | 3 ++ S2OJ/631/data/story2.out | 3 ++ S2OJ/631/data/story3.in | 3 ++ S2OJ/631/data/story3.out | 3 ++ S2OJ/631/data/story4.in | 3 ++ S2OJ/631/data/story4.out | 3 ++ S2OJ/631/data/story5.in | 3 ++ S2OJ/631/data/story5.out | 3 ++ S2OJ/631/data/story6.in | 3 ++ S2OJ/631/data/story6.out | 3 ++ S2OJ/631/data/story7.in | 3 ++ S2OJ/631/data/story7.out | 3 ++ S2OJ/631/data/story8.in | 3 ++ S2OJ/631/data/story8.out | 3 ++ S2OJ/631/data/story9.in | 3 ++ S2OJ/631/data/story9.out | 3 ++ 22 files changed, 126 insertions(+) create mode 100644 S2OJ/631/631.cpp create mode 100644 S2OJ/631/data/problem.conf create mode 100644 S2OJ/631/data/story1.in create mode 100644 S2OJ/631/data/story1.out create mode 100644 S2OJ/631/data/story10.in create mode 100644 S2OJ/631/data/story10.out create mode 100644 S2OJ/631/data/story2.in create mode 100644 S2OJ/631/data/story2.out create mode 100644 S2OJ/631/data/story3.in create mode 100644 S2OJ/631/data/story3.out create mode 100644 S2OJ/631/data/story4.in create mode 100644 S2OJ/631/data/story4.out create mode 100644 S2OJ/631/data/story5.in create mode 100644 S2OJ/631/data/story5.out create mode 100644 S2OJ/631/data/story6.in create mode 100644 S2OJ/631/data/story6.out create mode 100644 S2OJ/631/data/story7.in create mode 100644 S2OJ/631/data/story7.out create mode 100644 S2OJ/631/data/story8.in create mode 100644 S2OJ/631/data/story8.out create mode 100644 S2OJ/631/data/story9.in create mode 100644 S2OJ/631/data/story9.out diff --git a/S2OJ/631/631.cpp b/S2OJ/631/631.cpp new file mode 100644 index 00000000..9a0d9d4e --- /dev/null +++ b/S2OJ/631/631.cpp @@ -0,0 +1,63 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e7 + 5; + +int t, p, a, d, n; +int fac[N], inv[N], fac_inv[N]; + +constexpr int binpow(int a, int b, int mod) { + int res = 1; + a %= mod; + + 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 >> p; + + fac[0] = 1; + for (int i = 1; i < N; i++) { + fac[i] = static_cast(fac[i - 1]) * i % p; + } + + inv[0] = inv[1] = 1; + for (int i = 2; i < N; i++) { + inv[i] = static_cast(p - (p / i)) * inv[p % i] % p; + } + + fac_inv[0] = fac_inv[1] = 1; + for (int i = 2; i < N; i++) { + fac_inv[i] = static_cast(fac_inv[i - 1]) * inv[i] % p; + } + + while (t--) { + cin >> a >> d >> n; + + if (d == 0) { + cout << binpow(a, n, p) << endl; + } else { + int k = static_cast(a) * inv[d] % p; + + if (k == 0 || n + k - 1 > p) { + cout << 0 << endl; + } else { + cout << static_cast(fac[n + k - 1]) * fac_inv[k - 1] % p * binpow(d, n, p) % p << endl; + } + } + } + + return 0; +} diff --git a/S2OJ/631/data/problem.conf b/S2OJ/631/data/problem.conf new file mode 100644 index 00000000..a68f204c --- /dev/null +++ b/S2OJ/631/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abbc32d3baf7b5e6aeab884ca5984313c2f2a628364f57357a20d934f51ba4b2 +size 180 diff --git a/S2OJ/631/data/story1.in b/S2OJ/631/data/story1.in new file mode 100644 index 00000000..63784546 --- /dev/null +++ b/S2OJ/631/data/story1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0266e480a43389dccd535842f97e5c1f0225b51c226f9a7aa79258b8029d9a37 +size 886 diff --git a/S2OJ/631/data/story1.out b/S2OJ/631/data/story1.out new file mode 100644 index 00000000..90e48710 --- /dev/null +++ b/S2OJ/631/data/story1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:deae55060942f43c063808967cb849a9f162a2270e9086a36f073ffbafc35867 +size 242 diff --git a/S2OJ/631/data/story10.in b/S2OJ/631/data/story10.in new file mode 100644 index 00000000..d0060581 --- /dev/null +++ b/S2OJ/631/data/story10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82ffd7eaf7d7247dde8adc43e8a212e0599f4df03e489ce6d1631ef8f203ceed +size 23666879 diff --git a/S2OJ/631/data/story10.out b/S2OJ/631/data/story10.out new file mode 100644 index 00000000..4ccf7358 --- /dev/null +++ b/S2OJ/631/data/story10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e8334fbd0566edbd9c314e325eac7201c36df4664ae6255c5e632dfc495c19b +size 4947934 diff --git a/S2OJ/631/data/story2.in b/S2OJ/631/data/story2.in new file mode 100644 index 00000000..8e64c528 --- /dev/null +++ b/S2OJ/631/data/story2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31acf9aa6abcb5294f69ae8c69e9566feec32df9ba7c2ad2adb99e966072817e +size 1175 diff --git a/S2OJ/631/data/story2.out b/S2OJ/631/data/story2.out new file mode 100644 index 00000000..7f01859b --- /dev/null +++ b/S2OJ/631/data/story2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2ed5a342a00919a618eaa3454ddabe8f8b09c256c3a06f9cbb05b6d45b397e1 +size 289 diff --git a/S2OJ/631/data/story3.in b/S2OJ/631/data/story3.in new file mode 100644 index 00000000..4db14e75 --- /dev/null +++ b/S2OJ/631/data/story3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ae50294cd3aa5204d863db1fe59a998915c713f1765edb1d70ed5c310591702 +size 11696 diff --git a/S2OJ/631/data/story3.out b/S2OJ/631/data/story3.out new file mode 100644 index 00000000..00c2f81f --- /dev/null +++ b/S2OJ/631/data/story3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ede79dc6445f3936912001cb2901ac5eac166798017d0c0fef128e242a31ed2 +size 2937 diff --git a/S2OJ/631/data/story4.in b/S2OJ/631/data/story4.in new file mode 100644 index 00000000..45796ccb --- /dev/null +++ b/S2OJ/631/data/story4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b46ccddec8f3e8edbd3a2ca6573a9b4e5e9ddcff3516a08c37946f176e72af45 +size 14675 diff --git a/S2OJ/631/data/story4.out b/S2OJ/631/data/story4.out new file mode 100644 index 00000000..0d530aac --- /dev/null +++ b/S2OJ/631/data/story4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36131dddd4e4ebb80595d1761f5a8372f33206528317fcb07020742b08aae462 +size 3383 diff --git a/S2OJ/631/data/story5.in b/S2OJ/631/data/story5.in new file mode 100644 index 00000000..6efd8a45 --- /dev/null +++ b/S2OJ/631/data/story5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8e6be55e56b1a5cf9e56e079b7aab0125741145a3483ef10542c5fb26530637 +size 146726 diff --git a/S2OJ/631/data/story5.out b/S2OJ/631/data/story5.out new file mode 100644 index 00000000..418b3a35 --- /dev/null +++ b/S2OJ/631/data/story5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1534c320a071ac7804cd415f91379795f6e5866bd1818856a1290be573a5df4f +size 34297 diff --git a/S2OJ/631/data/story6.in b/S2OJ/631/data/story6.in new file mode 100644 index 00000000..5e1ace14 --- /dev/null +++ b/S2OJ/631/data/story6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa0851355865f7300fa417d713b6de5b7eac40a214583b57124b568909c2307 +size 176719 diff --git a/S2OJ/631/data/story6.out b/S2OJ/631/data/story6.out new file mode 100644 index 00000000..39a402dd --- /dev/null +++ b/S2OJ/631/data/story6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c892f425bbd8a728aa43ce7b01ed10d88caaf3dbab70daaf1140f56731c091e5 +size 39369 diff --git a/S2OJ/631/data/story7.in b/S2OJ/631/data/story7.in new file mode 100644 index 00000000..dbf8e184 --- /dev/null +++ b/S2OJ/631/data/story7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f159e14fb7f3017c58fc89a69fe0defa94047a8ebdaac74ac27770efdc55e0a +size 1766573 diff --git a/S2OJ/631/data/story7.out b/S2OJ/631/data/story7.out new file mode 100644 index 00000000..dba563ee --- /dev/null +++ b/S2OJ/631/data/story7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ebd6a3186a5e7ed15c111cb59536f851b889250e0724161dd3e914b8fe567e8 +size 393723 diff --git a/S2OJ/631/data/story8.in b/S2OJ/631/data/story8.in new file mode 100644 index 00000000..c0400d09 --- /dev/null +++ b/S2OJ/631/data/story8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59f70b49ab8b1d3b2813e1f7e8f074f87a26d1be4aa887a65ad4677d2702e643 +size 2066860 diff --git a/S2OJ/631/data/story8.out b/S2OJ/631/data/story8.out new file mode 100644 index 00000000..5e65f3a7 --- /dev/null +++ b/S2OJ/631/data/story8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27042ed34bc83d95110da05f90231c0ca5810ad38aee135e3faba37b4ac2d082 +size 444491 diff --git a/S2OJ/631/data/story9.in b/S2OJ/631/data/story9.in new file mode 100644 index 00000000..50abcb7f --- /dev/null +++ b/S2OJ/631/data/story9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:944b7bbb6a91029bcba2b5001b8c5a13474f09df58de4e1f284aa0d5424e7ae8 +size 20667273 diff --git a/S2OJ/631/data/story9.out b/S2OJ/631/data/story9.out new file mode 100644 index 00000000..1c997d6a --- /dev/null +++ b/S2OJ/631/data/story9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9b388c0d5bac61c0e1424ebe10de812001b462c576e96f2f9fd9b1e42d9d257 +size 4444470