QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67511 | #5099. 朝圣道 | iye | 0 | 2006ms | 9568kb | C++14 | 2.0kb | 2022-12-10 16:46:08 | 2022-12-10 16:47:01 |
Judging History
answer
#include "pilgrimage.h"
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define ll long long
// TODO: your functions
ll ksm(ll x, ll y, ll Mod) {
ll sum = 1;
for(; y; y >>= 1, x = x * x % Mod)
if(y & 1) sum = sum * x % Mod;
return sum;
}
ll mo, i2;
int p[20], c[20], pc[20], m = 0;
int qz[10][1000005], qu[10];
void init(int o, int ip) {
mo = ip;
i2 = (mo + 1) / 2;
for(int i = 2, j = mo; i <= j; ++i) {
if(j % i != 0) continue;
p[++m] = i, pc[m] = 1, c[m] = 0;
while(j % i == 0) {
pc[m] *= i, ++c[m];
j /= i;
}
}
fo(i, 1, m) {
qz[i][0] = 1;
fo(j, 1, pc[i]) {
qz[i][j] = qz[i][j - 1];
if(j % p[i] != 0)
(qz[i][j] *= j) %= mo;
}
qu[i] = qz[i][pc[i]];
}
return;
}
int Re[20];
ll exlucas(ll x, int id) {
if(x == 0) return 1;
ll res = qu[id] * exlucas(x / p[id], id) % pc[id];
res = ksm(res, x / pc[id], pc[id]);
res = res * qz[id][x % pc[id]] % mo;
return res;
}
void exgcd(ll a, ll b, ll &x, ll &y) {
if(!b) {
x = 1, y = 0; return;
}
ll nx, ny;
exgcd(b, a % b, nx, ny);
x = ny, y = nx - a / b * ny;
return;
}
void Merge(int &x, int &y, int nx, int ny) {
ll k1, k2;
int nny = y * ny;
exgcd(y, ny, k1, k2);
// printf("%d %d\n", k1, k2);
k1 = (k1 * (nx - x) % nny + nny) % nny;
x = (k1 * y + x) % nny;
y = nny;
return;
}
int ask(ll n) {
fo(i, 1, m) {
int stp = 0;
for(ll x = 2 * n; x; x /= p[i])
stp += x / p[i];
for(ll x = n; x; x /= p[i])
stp -= 2 * (x / p[i]);
if(stp >= c[i]) {Re[i] = 0; continue;}
ll z1 = exlucas(2 * n, i), z2 = exlucas(n, i);
z2 = z2 * z2 % pc[i];
z2 = ksm(z2, pc[i] / p[i] * (p[i] - 1) - 1, pc[i]);
// printf("%lld %lld %lld\n", z1, z2, ksm(p[i], stp, pc[i]));
Re[i] = z1 * z2 % pc[i] * ksm(p[i], stp, pc[i]) % pc[i];
// printf("%lld\n", Re[i]);
}
int u, o;
u = 0, o = 1;
fo(i, 1, m) {
Merge(u, o, Re[i], pc[i]);
}
// printf("%d %d\n", u, o);
u = u * (n % mo) % mo * ksm(i2, 2 * n, mo) % mo;
return u;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 507ms
memory: 9568kb
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:
5419 364275 514407 329394 364275 229662 53120 520095 520095 509260 514407 364275 509260 5419 277384 5419 520095 53120 5419 115262 229662 243797 115262 416076 229662 509260 53120 520095 115262 416076 229662 243797 416076 520095 329394 53120 416076 509260 509260 243797 5419 329394 115262 243797 520095...
result:
ok 910276 numbers
Test #2:
score: -4
Wrong Answer
time: 1381ms
memory: 7488kb
input:
1 972231 293475 7 1 9 6 5 1 11 5 5 12 2 2 7 3 4 10 10 3 2 10 7 1 10 9 1 3 5 6 7 2 7 4 1 10 1 9 3 10 10 2 6 11 4 10 12 8 5 2 12 4 9 12 7 2 12 4 3 1 2 9 12 1 4 5 6 12 6 5 9 2 5 12 3 4 6 12 12 2 1 6 4 12 10 5 12 7 9 8 3 8 10 5 3 6 12 7 7 10 7 10 8 7 7 2 2 4 8 6 10 8 11 6 11 10 3 9 5 2 5 1 10 2 11 4 4 3...
output:
270543 146738 239070 136857 151095 146738 123123 151095 151095 275457 220107 220107 270543 201765 88655 284960 284960 201765 220107 284960 270543 146738 284960 239070 146738 201765 151095 136857 270543 220107 270543 88655 146738 284960 146738 239070 201765 284960 284960 220107 136857 123123 88655 28...
result:
wrong answer 1st numbers differ - expected: '117936', found: '270543'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 6ms
memory: 6708kb
input:
3 1 334547 8234
output:
163947
result:
wrong answer 1st numbers differ - expected: '179079', found: '163947'
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: 2006ms
memory: 7860kb
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 30870 0 0 0 250369 0 0 0 0 0 438074 0 0 0 0 0 203224 0 0 0 0 0 0 0 0 0 53046 0 123165 0 0 0 214193 0 443898 0 0 0 0 0 0 0 0 0 0 208824 403956 0 0 0 0 0 0 0 0 0 0 201677 0 0 438984 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 120722 0 0 0 521913 0 0 0 0 0 0 0 0 0 0 0 485254 0 0 0 0 0 0 0 0 0...
result:
wrong answer 12th numbers differ - expected: '193620', found: '30870'
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 12ms
memory: 5396kb
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 73 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 201 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...
result:
wrong answer 25th numbers differ - expected: '204', found: '73'
Subtask #9:
score: 0
Skipped
Dependency #2:
0%