0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 21:48:48 +00:00

#631. 故事书(story)

https://sjzezoj.com/submission/71133
This commit is contained in:
Baoshuo Ren 2023-02-20 12:06:32 +08:00
parent f52f5f3a6c
commit a9dacf2e67
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 126 additions and 0 deletions

63
S2OJ/631/631.cpp Normal file
View File

@ -0,0 +1,63 @@
#include <iostream>
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<long long>(res) * a % mod;
a = static_cast<long long>(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<long long>(fac[i - 1]) * i % p;
}
inv[0] = inv[1] = 1;
for (int i = 2; i < N; i++) {
inv[i] = static_cast<long long>(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<long long>(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<long long>(a) * inv[d] % p;
if (k == 0 || n + k - 1 > p) {
cout << 0 << endl;
} else {
cout << static_cast<long long>(fac[n + k - 1]) * fac_inv[k - 1] % p * binpow(d, n, p) % p << endl;
}
}
}
return 0;
}

BIN
S2OJ/631/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/631/data/story9.out (Stored with Git LFS) Normal file

Binary file not shown.