QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#150400 | #4166. 古代猪文 | NOI_AK_ME | 100 ✓ | 1ms | 3796kb | C++23 | 2.1kb | 2023-08-25 16:53:02 | 2023-08-25 16:53:03 |
Judging History
answer
#include <cstdio>
#include <cassert>
#include <iostream>
using std::cin;
using std::cout;
using ll = long long;
namespace number_theory {
constexpr int MOD = 999911659;
int frac_[35616], *const frac = frac_ - 1;
static int init__ = []() {
frac[1] = 1;
for (int i = 2; i < 35617; i++) {
frac[i] = frac[i - 1] * 1ll * i % (MOD - 1);
}
return 0;
}();
ll qp(ll x, ll t, int mod) {
ll ans = 1;
while (t) {
if (t & 1)
ans = (ans * x) % mod;
x = x * x % mod;
t >>= 1;
}
return ans;
}
ll lucas(ll n, ll m, ll p, bool noloop = false) {
if (!m)
return 1;
if (n < m)
return 0;
if (n == m)
return 1;
if (!noloop)
return lucas(n % p, m % p, p, true) * 1ll * lucas(n / p, m / p, p) % p;
return frac[n] * 1ll * qp(frac[n - m], p - 2, p) % p * qp(frac[m], p - 2, p) % p;
}
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1, y = 0;
return a;
}
ll g = exgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
void excrt(ll &a, ll &x, ll b, ll y) {
ll n, m;
ll g = exgcd(x, y, n, m);
assert((b - a) % g == 0);
n *= (b - a) / g;
a = a + x * n;
x = x * y / g;
a %= x;
}
}
namespace m {
int in, ig;
using namespace number_theory;
int solve(int x) {
ll a = 0, b, xx = 1, yy;
for (int i : {
2, 3, 4679, 35617
}) {
b = lucas(in, x, i);
yy = i;
excrt(a, xx, b, yy);
}
return a;
}
void work() {
cin >> in >> ig;
if (ig % MOD == 0) {
cout << 0;
return;
}
int ans = 0;
for (int i = 1; i * i <= in; i++) {
if (in % i)
continue;
ans += solve(i);
ans %= (MOD - 1);
if (i * i != in) {
ans += solve(in / i);
ans %= (MOD - 1);
}
}
cout << qp(ig, (ans + MOD - 1) % (MOD - 1), MOD) << '\n';
}
}
int main() {
m::work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 3692kb
input:
24 227655187
output:
268407382
result:
ok single line: '268407382'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3704kb
input:
48 162572551
output:
844226850
result:
ok single line: '844226850'
Test #3:
score: 5
Accepted
time: 1ms
memory: 3736kb
input:
420 156955809
output:
866130752
result:
ok single line: '866130752'
Test #4:
score: 5
Accepted
time: 1ms
memory: 3796kb
input:
984 175422269
output:
301639070
result:
ok single line: '301639070'
Test #5:
score: 5
Accepted
time: 1ms
memory: 3708kb
input:
15015 16515289
output:
955216017
result:
ok single line: '955216017'
Test #6:
score: 5
Accepted
time: 1ms
memory: 3696kb
input:
24633 806082456
output:
279303401
result:
ok single line: '279303401'
Test #7:
score: 5
Accepted
time: 1ms
memory: 3780kb
input:
52311 614403721
output:
711757654
result:
ok single line: '711757654'
Test #8:
score: 5
Accepted
time: 1ms
memory: 3736kb
input:
62370 34849907
output:
625045294
result:
ok single line: '625045294'
Test #9:
score: 5
Accepted
time: 0ms
memory: 3712kb
input:
753447601 45941770
output:
598569129
result:
ok single line: '598569129'
Test #10:
score: 5
Accepted
time: 1ms
memory: 3644kb
input:
945764054 242359537
output:
846078071
result:
ok single line: '846078071'
Test #11:
score: 5
Accepted
time: 1ms
memory: 3796kb
input:
945764058 295965211
output:
189097853
result:
ok single line: '189097853'
Test #12:
score: 5
Accepted
time: 0ms
memory: 3668kb
input:
945764146 174114001
output:
615490219
result:
ok single line: '615490219'
Test #13:
score: 5
Accepted
time: 0ms
memory: 3704kb
input:
223092870 378256627
output:
463324931
result:
ok single line: '463324931'
Test #14:
score: 5
Accepted
time: 1ms
memory: 3784kb
input:
248834355 266664277
output:
569037366
result:
ok single line: '569037366'
Test #15:
score: 5
Accepted
time: 1ms
memory: 3792kb
input:
746503065 188518317
output:
194042372
result:
ok single line: '194042372'
Test #16:
score: 5
Accepted
time: 1ms
memory: 3676kb
input:
386122275 139473405
output:
7561904
result:
ok single line: '7561904'
Test #17:
score: 5
Accepted
time: 1ms
memory: 3704kb
input:
900951975 90523153
output:
81793986
result:
ok single line: '81793986'
Test #18:
score: 5
Accepted
time: 1ms
memory: 3708kb
input:
797986035 866545121
output:
101524549
result:
ok single line: '101524549'
Test #19:
score: 5
Accepted
time: 0ms
memory: 3712kb
input:
669278610 398361241
output:
253531581
result:
ok single line: '253531581'
Test #20:
score: 5
Accepted
time: 1ms
memory: 3792kb
input:
999911657 999911659
output:
0
result:
ok single line: '0'