QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368932 | #5099. 朝圣道 | zyc070419 | 0 | 2290ms | 15968kb | C++20 | 3.8kb | 2024-03-27 18:16:29 | 2024-03-27 18:16:31 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
#include "pilgrimage.h"
using namespace std;
int mod, inv, Phi = 1;
inline int add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
inline int del(int x, int y) {x -= y; return x < 0 ? x + mod : x;}
inline void Add(int &x, int y) {x = add(x, y);}
inline void Del(int &x, int y) {x = del(x, y);}
inline int qpow(int x, ll y) {
if (y >= Phi) y %= Phi, y += Phi;
int res = 1;
while (y) {
if (y & 1ll) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
namespace my_ex_Lucas {
struct node {
int p, c, pw, m, im, phi;
vector<int> pre, qpw, iv;
};
int p, cnt;
node a[20];
void ex_gcd(int A, int B, int &x, int &y) {
if (!B) return x = 1, y = 0, void();
int xx, yy;
ex_gcd(B, A % B, xx, yy);
x = yy; y = xx - A / B * yy;
}
inline int get_inv(int v, int mod) {
int x, y;
ex_gcd(v, mod, x, y);
x = (x % mod + mod) % mod;
assert(1ll * v * x % mod == 1);
return x;
}
void init(int P) {
int x = p = P; cnt = 0;
for (int i = 2; i * i <= x; ++i) {
if (x % i) continue;
int num = 0, now = 1;
while (x % i == 0) num++, now *= i, x /= i;
cnt++;
a[cnt].p = i; a[cnt].c = num; a[cnt].pw = now; a[cnt].m = p / now; a[cnt].im = get_inv(a[cnt].m % a[cnt].pw, a[cnt].pw);
a[cnt].phi = now - now / i;
a[cnt].pre.resize(now);
a[cnt].pre[0] = 1;
for (int j = 1; j < now; ++j) a[cnt].pre[j] = 1ll * a[cnt].pre[j - 1] * (j % i == 0 ? 1 : j) % now;
a[cnt].qpw.resize(a[cnt].phi * 2);
a[cnt].qpw[0] = 1;
for (int j = 1; j < a[cnt].phi * 2; ++j) a[cnt].qpw[j] = 1ll * a[cnt].qpw[j - 1] * a[cnt].pre[now - 1] % now;
a[cnt].iv.resize(now);
for (int j = 1; j < now; ++j)
if (j % i) a[cnt].iv[j] = get_inv(j, now);
Phi *= a[cnt].phi;
}
if (x > 1) {
Phi *= x;
cnt++;
a[cnt].p = x; a[cnt].c = 1; a[cnt].pw = x; a[cnt].m = p / x; a[cnt].im = get_inv(a[cnt].m % a[cnt].pw, a[cnt].pw);
a[cnt].phi = x - 1;
a[cnt].pre.resize(x);
a[cnt].pre[0] = 1;
for (int j = 1; j < x; ++j) a[cnt].pre[j] = 1ll * a[cnt].pre[j - 1] * j % x;
a[cnt].qpw.resize(a[cnt].phi * 2);
a[cnt].qpw[0] = 1;
for (int j = 1; j < a[cnt].phi * 2; ++j) a[cnt].qpw[j] = 1ll * a[cnt].qpw[j - 1] * a[cnt].pre[x - 1] % x;
a[cnt].iv.resize(x);
for (int j = 1; j < x; ++j) a[cnt].iv[j] = get_inv(j, x);
}
}
int calc(ll n, int id) {
ll mem = n / a[id].pw;
if (mem >= a[id].phi) mem = mem % a[id].phi + a[id].phi;
return 1ll * a[id].qpw[mem] * a[id].pre[n % a[id].pw] % a[id].pw;
}
int work(ll n, ll m, int id) {
int o = 0, res = 1, ire = 1;
res = calc(n, id);
ire = 1ll * calc(m, id) * calc(n - m, id) % a[id].pw;
for (ll now = a[id].p; now <= n; now *= (ll)a[id].p) {
o += n / now - m / now - (n - m) / now;
res = 1ll * res * calc(n / now, id) % a[id].pw;
ire = 1ll * ire * calc(m / now, id) % a[id].pw * calc((n - m) / now, id) % a[id].pw;
}
res = 1ll * res * a[id].iv[ire] % a[id].pw;
if (o >= a[id].c) return 0;
while (o--) res = 1ll * res * a[id].p % a[id].pw;
return res;
}
int ex_Lucas(ll n, ll m) {
if (n < 0 || m < 0 || n < m) return 0;
int res = 0;
for (int i = 1; i <= cnt; ++i) {
int tmp = work(n, m, i);
res = (res + 1ll * tmp * a[i].m % p * a[i].im % p) % p;
}
return res;
}
}
using my_ex_Lucas :: ex_Lucas;
void init(int o, int p) {
mod = p;
inv = (mod + 1) / 2;
my_ex_Lucas :: init(p);
}
int ask(ll n) {
if (n == 1) return inv;
n--;
int val = (2ll * n - 1) % mod;
val = 8ll * val * (val + 2) % mod;
int tmp1 = ex_Lucas(2ll * n - 2, n - 1);
int tmp2 = ex_Lucas(2ll * n - 2, n - 2);
val = 1ll * val * del(tmp1, tmp2) % mod;
val = 1ll * val * qpow(inv, 2ll * n + 3);
return val;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 142ms
memory: 15968kb
input:
1 910276 554767 6 10 7 4 10 12 9 3 3 5 7 10 5 6 1 6 3 9 6 8 12 11 8 2 12 5 9 3 8 2 12 11 2 3 4 9 2 5 5 11 6 4 8 11 3 9 2 2 8 9 2 8 9 6 2 9 2 10 10 7 5 6 4 4 11 12 8 8 2 2 4 3 3 5 6 6 8 11 6 9 9 3 4 1 2 2 6 9 9 2 3 2 12 6 1 7 2 4 12 11 4 7 6 3 9 4 6 5 3 3 12 6 2 1 1 7 2 6 5 9 11 6 3 4 11 1 2 4 5 4 10...
output:
1550579184 1346489428 196541248 10315200 1346489428 | 605475377 8841600 8841600 11604600 196541248 1346489428 11604600 1550579184 277384 1550579184 8841600 605475377 1550579184 1744496800 | e 1744496800 7073280 | 11604600 605475377 8841600 1744496800 7073280 | e 7073280 8841600 10315200 605475377 70...
result:
wrong answer 1st numbers differ - expected: '5419', found: '1550579184'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 33ms
memory: 10432kb
input:
3 1 334547 8234
output:
\x05
result:
wrong output format Expected integer, but "\x05" found
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 2290ms
memory: 8240kb
input:
6 958477 522361 280121915553826833 734266539148641647 72849162479700582 274266741463686096 60278972064195458 828423669427600612 571432949203039978 518511460268700898 486268614705621285 19216283231217074 611458416727512530 175147354285288662 799769622289998997 400123443628688299 145546980862133838 40...
output:
0 0 0 0 0 0 0 0 0 0 0 400306176 0 0 0 e 0 0 0 0 0 548419220 0 0 0 0 0 1789258288 0 0 0 0 0 0 0 0 0 W 0 35180762 0 0 0
result:
wrong answer 12th numbers differ - expected: '193620', found: '400306176'
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 9ms
memory: 5716kb
input:
8 9963 251 831797004675585320 494759973681332858 701341496127272302 252910460485222469 250965009655458584 366193481309061299 633134388675839346 791999098066205672 196620805863610860 363773642045280947 466508590762410710 407790578717064135 181590911404670570 570642047249889864 70138464625729452 23634...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45441 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 755 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 25th numbers differ - expected: '204', found: '45441'
Subtask #9:
score: 0
Skipped
Dependency #1:
0%