QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#367648#5099. 朝圣道zzafanti20 1189ms5908kbC++232.0kb2024-03-26 11:23:252024-03-26 11:23:25

Judging History

你现在查看的是最新测评结果

  • [2024-03-26 11:23:25]
  • 评测
  • 测评结果:20
  • 用时:1189ms
  • 内存:5908kb
  • [2024-03-26 11:23:25]
  • 提交

answer

#include<bits/stdc++.h>
#include "pilgrimage.h"
using namespace std;
using E=long long;

E mod;
vector<pair<int,int>> divsp;
vector<int> val;

E ksm(E a,E b,E MOD){
  //cerr<<"b="<<b<<endl;
  E ret=1;
  a%=MOD;
  while(b){
    if(b&1) ret=ret*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return ret;
}

E exgcd(E a,E b,E &x,E &y){
  if(!b){
    return x=1,y=0,a;
  }
  E d=exgcd(b,a%b,y,x);
  return y-=a/b*x,d;
}

E inverse(E a,E mod){
  assert(__gcd(a,mod)==1);
  a%=mod;
  assert(a!=0);
  E X=0,Y=0;
  E d=exgcd(a,mod,X,Y);
  return (X%mod+mod)%mod;
}

E calcu(E n,E p,E q,E pq){
  if(n==0) return 1;
  E ret=1;
  for(int i=1; i<=(n%pq); i++){
    if(i%p) ret=ret*i%pq;
  }
  E x=1;
  for(int i=1; i<pq; i++){
    if(i%p) x=x*i%pq;
  }
  ret=ret*ksm(x,n/pq,pq)%pq;
  ret=ret*calcu(n/p,p,q,pq)%pq;
  return ret;
}

E get(E n,E p){
  E ret=0;
  __int128 bs=p;
  while(bs<=n){
    ret+=n/bs;
    bs*=p;
  }
  return ret;
}

E C(E n,E m,E p,E q){
  E x=0,y=0,z=0;
  E pq=1;
  for(int j=0; j<q; j++) pq*=p;
  return calcu(n,p,q,pq)*inverse(calcu(m,p,q,pq),pq)%pq*inverse(calcu(n-m,p,q,pq),pq)%pq*ksm(p,get(n,p)-get(m,p)-get(n-m,p),pq)%pq;
}

E CRT(E n,E m){
  if(n<0||m<0||n<m) return 0;
  if(n==0||m==0) return 1;
  E ret=0,M=1;
  for(auto p:val) M=M*p;
  for(int i=0; i<(int)divsp.size(); i++){
    E dM=M/val[i];
    E tmp=C(n,m,divsp[i].first,divsp[i].second);
    ret=(ret+tmp*dM%M*inverse(dM,val[i])%M)%M;
  }
  return ret;
}

void init(int o,int p){
  mod=p;
  for(int i=2; i*i<=p; i++){
    if(p%i) continue;
    int s=0; int x=1;
    while(p%i==0) x*=i,s++,p/=i;
    val.emplace_back(x);
    divsp.emplace_back(make_pair(i,s));
  }
  if(p>1){
    val.emplace_back(p);
    divsp.emplace_back(make_pair(p,1));
  }
}

int ask(long long n){
  if(n==1) return inverse(2,mod);
  E t1=CRT(2*n-4,n-2)-CRT(2*n-4,n-3)+mod;
  t1%=mod;
  t1=t1*4%mod*(2*n%mod-3)%mod*(2*n%mod-1)%mod;
  t1=t1*ksm(inverse(4,mod),n,mod)%mod;
  return t1;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 12
Accepted

Test #5:

score: 12
Accepted
time: 14ms
memory: 5604kb

input:

3 1 334547
8234

output:

179079

result:

ok 1 number(s): "179079"

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #3:

100%
Accepted

Test #6:

score: 0
Time Limit Exceeded

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:

Unauthorized output

result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

6 958477 522361
280121915553826833
734266539148641647
72849162479700582
274266741463686096
60278972064195458
828423669427600612
571432949203039978
518511460268700898
486268614705621285
19216283231217074
611458416727512530
175147354285288662
799769622289998997
400123443628688299
145546980862133838
40...

output:

Unauthorized output

result:


Subtask #7:

score: 8
Accepted

Dependency #3:

100%
Accepted

Test #13:

score: 8
Accepted
time: 2ms
memory: 5584kb

input:

7 1 731039
314313205082038759

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 0ms
memory: 5668kb

input:

7 1 587945
675184352277027016

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 24ms
memory: 5572kb

input:

7 1 732151
522404464427087971

output:

0

result:

ok 1 number(s): "0"

Test #16:

score: 0
Accepted
time: 1ms
memory: 5664kb

input:

7 1 952025
865782493150981281

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 3ms
memory: 5604kb

input:

7 1 151005
80048698775676684

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 0ms
memory: 5652kb

input:

7 1 819153
214538328031265195

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

7 1 84501
605460166753167761

output:

0

result:

ok 1 number(s): "0"

Test #20:

score: 0
Accepted
time: 1ms
memory: 5832kb

input:

7 1 579977
434091105518396762

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

7 1 161075
649828935660369724

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 1ms
memory: 5632kb

input:

7 1 629595
216539117331686464

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 2ms
memory: 5668kb

input:

7 1 317005
831315176686118434

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 1ms
memory: 5640kb

input:

7 1 204399
934354294367869212

output:

0

result:

ok 1 number(s): "0"

Test #25:

score: 0
Accepted
time: 2ms
memory: 5608kb

input:

7 1 98233
515248809013032256

output:

0

result:

ok 1 number(s): "0"

Test #26:

score: 0
Accepted
time: 1ms
memory: 5640kb

input:

7 1 738315
930635383520033839

output:

51840

result:

ok 1 number(s): "51840"

Test #27:

score: 0
Accepted
time: 0ms
memory: 5908kb

input:

7 1 404535
557582195171952455

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 1ms
memory: 5656kb

input:

7 1 277475
413241759909529359

output:

0

result:

ok 1 number(s): "0"

Test #29:

score: 0
Accepted
time: 3ms
memory: 5840kb

input:

7 1 206409
381910309127041513

output:

0

result:

ok 1 number(s): "0"

Test #30:

score: 0
Accepted
time: 140ms
memory: 5660kb

input:

7 1 694649
641706538274033333

output:

0

result:

ok 1 number(s): "0"

Test #31:

score: 0
Accepted
time: 42ms
memory: 5652kb

input:

7 1 974065
700551256691343002

output:

0

result:

ok 1 number(s): "0"

Test #32:

score: 0
Accepted
time: 1ms
memory: 5660kb

input:

7 1 966571
5339566589982367

output:

0

result:

ok 1 number(s): "0"

Subtask #8:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 1189ms
memory: 5680kb

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
204
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
63
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 output format Expected integer, but "

Subtask #9:

score: 0
Skipped

Dependency #1:

0%