QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#457477 | #5099. 朝圣道 | Kevin5307 | 30 | 1516ms | 16232kb | C++23 | 2.0kb | 2024-06-29 12:44:20 | 2024-06-29 12:44:20 |
Judging History
answer
#include<bits/stdc++.h>
#include"pilgrimage.h"
using namespace std;
using ll=long long;
ll ksm(ll a,ll b,ll mod)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
class exLucas
{
int pr[20],cnt[20],tot;
ll P;
ll val[20];
ll rem[20];
ll pval[20];
vector<ll> prod[20];
void exgcd(ll x,ll y,ll &a,ll &b)
{
if(!y)
{
a=1;
b=0;
return ;
}
exgcd(y,x%y,b,a);
b-=a*(x/y);
}
ll inverse(ll x,ll m)
{
ll a,b;
exgcd(x,m,a,b);
return (a%m+m)%m;
}
void initCrt()
{
for(int i=0;i<tot;i++)
val[i]=P/pval[i]*inverse(P/pval[i],pval[i]);
}
ll crt()
{
ll ans=0;
for(int i=0;i<tot;i++)
ans=(ans+rem[i]*val[i])%P;
return ans;
}
ll cntp(ll n,ll p)
{
if(!n) return 0;
return n/p+cntp(n/p,p);
}
ll calc(ll x,ll pr,ll pval,int ind)
{
if(!x) return 1;
ll s=((x/pval)&1)?(pval-1):1;
s=s*prod[ind][x%pval];
return s*calc(x/pr,pr,pval,ind)%pval;
}
public:
void init(int p)
{
P=p;
tot=0;
for(int i=2;i*i<=p;i++)
if(p%i==0)
{
pr[tot]=i;
pval[tot]=1;
while(p%i==0)
{
p/=i;
pval[tot]*=i;
cnt[tot]++;
}
tot++;
}
if(p>1)
{
pr[tot]=p;
pval[tot]=p;
cnt[tot++]=1;
}
for(int i=0;i<tot;i++)
{
prod[i]={1};
for(int j=1;j<pval[i];j++)
if(j%pr[i]==0)
prod[i].push_back(prod[i].back());
else
prod[i].push_back(prod[i].back()*j%pval[i]);
}
initCrt();
}
exLucas(){}
exLucas(int p){init(p);}
ll calc(ll n,ll m)
{
for(int i=0;i<tot;i++)
{
ll cp=cntp(n,pr[i])-cntp(m,pr[i])-cntp(n-m,pr[i]);
rem[i]=calc(n,pr[i],pval[i],i)%pval[i]*inverse(calc(m,pr[i],pval[i],i),pval[i])*inverse(calc(n-m,pr[i],pval[i],i),pval[i])%pval[i];
}
return crt();
}
};
exLucas exLucasCalculator;
ll p;
void init(int o,int p)
{
::p=p;
exLucasCalculator.init(p);
}
int ask(ll n)
{
ll inv=ksm((p+1)/2,n+n,p);
return inv*(n%p)*exLucasCalculator.calc(n+n,n)%p;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 138ms
memory: 15288kb
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: 0
Wrong Answer
time: 383ms
memory: 7572kb
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:
238336 146738 140514 163689 237740 146738 174938 237740 237740 245142 24457 24457 238336 49158 71326 100060 100060 49158 24457 100060 238336 146738 100060 140514 146738 49158 237740 163689 238336 24457 238336 71326 146738 100060 146738 140514 49158 100060 100060 24457 163689 174938 71326 100060 2451...
result:
wrong answer 1st numbers differ - expected: '117936', found: '238336'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 12
Accepted
Test #5:
score: 12
Accepted
time: 0ms
memory: 9956kb
input:
3 1 334547 8234
output:
179079
result:
ok 1 number(s): "179079"
Subtask #4:
score: 18
Accepted
Dependency #3:
100%
Accepted
Test #6:
score: 18
Accepted
time: 398ms
memory: 16232kb
input:
4 1000000 581873 49881 62491 206405 26106 129239 174098 141494 61402 149825 241992 8109 243567 71918 203927 278575 263516 143582 32237 195508 269119 9111 105700 80919 229859 150334 171917 78447 62500 190063 138903 6395 222902 118653 136505 242467 64984 170330 287622 27089 35823 107672 273459 188857 ...
output:
225562 278095 494263 533616 449513 172629 433105 169217 156602 470240 127840 224903 148625 143635 385698 428034 270424 224704 326598 317786 205590 556103 563899 492571 87003 417735 350849 476300 65308 462020 373541 56205 35476 425631 345156 395965 377993 402141 119653 299737 4555 400632 420936 58015...
result:
ok 1000000 numbers
Subtask #5:
score: 0
Wrong Answer
Dependency #4:
100%
Accepted
Test #7:
score: 0
Wrong Answer
time: 883ms
memory: 15636kb
input:
5 1000000 840643 596357868225427095 792903040511847841 549819683428503148 982786835970534376 855138540813992974 101968907510306081 885121351101383723 127972727417081251 728407510651610501 998897446686193527 889398142082696651 17276066104970301 87773104284997915 716559595019194816 538865162230963483 ...
output:
646924 149057 63734 125684 266228 294243 13853 204048 169981 228343 618602 241533 403028 444568 750856 374964 243219 264897 732729 264397 271114 533927 326803 794246 379491 149146 674660 484830 723668 282454 311655 41768 123449 5616 670015 171419 611949 203696 491889 132569 304678 550597 310490 7891...
result:
wrong answer 1st numbers differ - expected: '0', found: '646924'
Subtask #6:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 1516ms
memory: 7880kb
input:
6 958477 522361 280121915553826833 734266539148641647 72849162479700582 274266741463686096 60278972064195458 828423669427600612 571432949203039978 518511460268700898 486268614705621285 19216283231217074 611458416727512530 175147354285288662 799769622289998997 400123443628688299 145546980862133838 40...
output:
278707 396455 320744 390321 242949 239544 75204 111571 270364 92569 499260 268243 102564 85894 490765 436672 289743 188464 468330 114632 262214 339083 480857 474194 147481 206708 264894 383891 327244 121622 425344 87919 215856 180495 449778 345311 29848 367880 311623 516922 239761 222443 25156 39694...
result:
wrong answer 1st numbers differ - expected: '0', found: '278707'
Subtask #7:
score: 0
Wrong Answer
Dependency #3:
100%
Accepted
Test #13:
score: 0
Wrong Answer
time: 1ms
memory: 5580kb
input:
7 1 731039 314313205082038759
output:
77286
result:
wrong answer 1st numbers differ - expected: '0', found: '77286'
Subtask #8:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 9ms
memory: 5640kb
input:
8 9963 251 831797004675585320 494759973681332858 701341496127272302 252910460485222469 250965009655458584 366193481309061299 633134388675839346 791999098066205672 196620805863610860 363773642045280947 466508590762410710 407790578717064135 181590911404670570 570642047249889864 70138464625729452 23634...
output:
44 235 58 134 218 145 17 50 182 3 67 148 107 93 235 190 223 29 243 245 106 44 27 99 204 231 98 224 188 150 141 175 3 86 99 60 223 133 232 36 3 242 3 122 222 64 244 170 73 167 174 247 232 207 134 117 64 156 89 104 167 8 44 134 131 80 201 168 163 235 47 205 41 240 59 227 201 147 168 10 20 115 57 30 72...
result:
wrong answer 1st numbers differ - expected: '0', found: '44'
Subtask #9:
score: 0
Skipped
Dependency #1:
0%