QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67132#5099. 朝圣道aoui24 1663ms7620kbC++142.9kb2022-12-10 09:49:452022-12-10 09:49:47

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 09:49:47]
  • Judged
  • Verdict: 24
  • Time: 1663ms
  • Memory: 7620kb
  • [2022-12-10 09:49:45]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
void exgcd(ll a,ll b,ll &x,ll &y){
    if (!b) return (void)(x=1,y=0);
    exgcd(b,a%b,x,y);
    ll tmp=x;x=y;y=tmp-a/b*y;
}
ll gcd(ll a,ll b){
    if (b==0) return a;
    return gcd(b,a%b); 
}
inline ll INV(ll a,ll p){
    ll x,y;
    exgcd(a,p,x,y);
    return (x+p)%p;
}
inline ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
inline ll mabs(ll x){
    return (x>0?x:-x);
}
inline ll fast_mul(ll a,ll b,ll p){
    ll t=0;a%=p;b%=p;
    while (b){
        if (b&1LL) t=(t+a)%p;
        b>>=1LL;a=(a+a)%p;
    }
    return t;
}
inline ll fast_pow(ll a,ll b,ll p){
    ll t=1;a%=p;
    while (b){
        if (b&1LL) t=(t*a)%p;
        b>>=1LL;a=(a*a)%p;
    }
    return t;
}
inline ll F(ll n,ll P,ll PK){
    if (n==0) return 1;
    ll rou=1;
    ll rem=1;
    for (ll i=1;i<=PK;i++){
        if (i%P) rou=rou*i%PK;
    }
    rou=fast_pow(rou,n/PK,PK);
    for (ll i=PK*(n/PK);i<=n;i++){
        if (i%P) rem=rem*(i%PK)%PK;
    }
    return F(n/P,P,PK)*rou%PK*rem%PK;
}
inline ll G(ll n,ll P){
    if (n<P) return 0;
    return G(n/P,P)+(n/P);
}
inline ll C_PK(ll n,ll m,ll P,ll PK){
    ll fz=F(n,P,PK),fm1=INV(F(m,P,PK),PK),fm2=INV(F(n-m,P,PK),PK);
    ll mi=fast_pow(P,G(n,P)-G(m,P)-G(n-m,P),PK);
    return fz*fm1%PK*fm2%PK*mi%PK;
}
ll A[1001],B[1001];
inline ll exLucas(ll n,ll m,ll P){
    ll ljc=P,tot=0;
    for (ll tmp=2;tmp*tmp<=P;tmp++){
        if (!(ljc%tmp)){
            ll PK=1;
            while (!(ljc%tmp)){
                PK*=tmp;ljc/=tmp;
            }
            A[++tot]=PK;B[tot]=C_PK(n,m,tmp,PK);
        }
    }
    if (ljc!=1){
        A[++tot]=ljc;B[tot]=C_PK(n,m,ljc,ljc);
    }
    ll ans=0;
    for (ll i=1;i<=tot;i++){
        ll M=P/A[i],T=INV(M,A[i]);
        ans=(ans+B[i]*M%P*T%P)%P;
    }
    return ans;
}

ll P,C[1001],D[1001],tot,ph,mm,M[1001],T[1001];
void init (int o, int p)
{
	ph=P=p;
	ll ljc=P;
	tot=0;
    for (ll tmp=2;tmp*tmp<=P;tmp++){
        if (!(ljc%tmp)){
            ll PK=1;
            ph=ph/tmp*(tmp-1);
            while (!(ljc%tmp)){
                PK*=tmp;ljc/=tmp;
            }
            A[++tot]=PK;
            C[tot]=tmp;
            D[tot]=PK;
//			B[tot]=C_PK(n,m,tmp,PK);
        }
    }
    if (ljc!=1){
        A[++tot]=ljc;
        C[tot]=D[tot]=ljc;
        ph=ph/ljc*(ljc-1);
//		B[tot]=C_PK(n,m,ljc,ljc);
    }
    for (ll i=1;i<=tot;i++){
    	M[i]=P/A[i];T[i]=INV(M[i],A[i]);
    }
    mm=fast_pow(4,ph-1,P);
}

#include<map>
map<long long,int> ma;

int ask (long long n)
{
	if(ma[n])return ma[n];
	for(int i=1;i<=tot;i++)B[i]=C_PK(2*n,n,C[i],D[i]);
	ll ans=0;
    for (ll i=1;i<=tot;i++){
        ans=(ans+B[i]*M[i]%P*T[i]%P)%P;
    }
    ans=n%P*ans%P;
    ll h=gcd(n,ph);
    if(h==1)ans=ans*fast_pow(mm,n%ph,P)%P;
    else if(n>=ph)ans=ans*fast_pow(mm,n%ph+ph,P)%P;
    else ans=ans*fast_pow(mm,n,P)%P;
    return ma[n]=ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 343ms
memory: 7488kb

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
Accepted
time: 53ms
memory: 7620kb

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:

117936
146738
29445
289464
209790
146738
240513
209790
209790
158067
220107
220107
117936
201765
284305
145210
145210
201765
220107
145210
117936
146738
145210
29445
146738
201765
209790
289464
117936
220107
117936
284305
146738
145210
146738
29445
201765
145210
145210
220107
289464
240513
284305
14...

result:

ok 972231 numbers

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #3:

score: 0
Time Limit Exceeded

input:

2 957481 386233
816
1256
2812
1370
1469
1439
33
929
1437
2680
1001
1846
1936
1161
1823
1417
2823
1753
2434
577
1671
676
174
2401
1762
123
785
604
1650
117
2344
1365
221
1096
1087
1057
457
2254
647
1827
266
1599
1445
83
2685
1372
1795
2595
1909
2605
1608
2656
1114
581
725
725
2964
1893
2997
2159
2457...

output:

Unauthorized output

result:


Subtask #3:

score: 12
Accepted

Test #5:

score: 12
Accepted
time: 15ms
memory: 3496kb

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: 3ms
memory: 3532kb

input:

7 1 731039
314313205082038759

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 5ms
memory: 3276kb

input:

7 1 587945
675184352277027016

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 34ms
memory: 3536kb

input:

7 1 732151
522404464427087971

output:

0

result:

ok 1 number(s): "0"

Test #16:

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

input:

7 1 952025
865782493150981281

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 6ms
memory: 3500kb

input:

7 1 151005
80048698775676684

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 4ms
memory: 3288kb

input:

7 1 819153
214538328031265195

output:

0

result:

ok 1 number(s): "0"

Test #19:

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

input:

7 1 84501
605460166753167761

output:

0

result:

ok 1 number(s): "0"

Test #20:

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

input:

7 1 579977
434091105518396762

output:

0

result:

ok 1 number(s): "0"

Test #21:

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

input:

7 1 161075
649828935660369724

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

7 1 629595
216539117331686464

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 4ms
memory: 3280kb

input:

7 1 317005
831315176686118434

output:

0

result:

ok 1 number(s): "0"

Test #24:

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

input:

7 1 204399
934354294367869212

output:

0

result:

ok 1 number(s): "0"

Test #25:

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

input:

7 1 98233
515248809013032256

output:

0

result:

ok 1 number(s): "0"

Test #26:

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

input:

7 1 738315
930635383520033839

output:

51840

result:

ok 1 number(s): "51840"

Test #27:

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

input:

7 1 404535
557582195171952455

output:

0

result:

ok 1 number(s): "0"

Test #28:

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

input:

7 1 277475
413241759909529359

output:

0

result:

ok 1 number(s): "0"

Test #29:

score: 0
Accepted
time: 6ms
memory: 3428kb

input:

7 1 206409
381910309127041513

output:

0

result:

ok 1 number(s): "0"

Test #30:

score: 0
Accepted
time: 191ms
memory: 3372kb

input:

7 1 694649
641706538274033333

output:

0

result:

ok 1 number(s): "0"

Test #31:

score: 0
Accepted
time: 58ms
memory: 3276kb

input:

7 1 974065
700551256691343002

output:

0

result:

ok 1 number(s): "0"

Test #32:

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

input:

7 1 966571
5339566589982367

output:

0

result:

ok 1 number(s): "0"

Subtask #8:

score: 0
Time Limit Exceeded

Test #33:

score: 16
Accepted
time: 1663ms
memory: 4316kb

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:

ok 9963 numbers

Test #34:

score: -16
Time Limit Exceeded

input:

8 9967 6043
820328543276206812
181987384710842549
607221769552657162
341958396909446562
323372299362111304
912735937493462137
261510727281638358
792961465908198578
724729139273707925
61144688983588693
803871679975888144
565482268842659147
653581946336745517
701605486107526593
237425098688490866
3911...

output:

Unauthorized output

result:


Subtask #9:

score: 0
Skipped

Dependency #2:

0%