QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67122#5099. 朝圣道aoui12 1346ms3680kbC++142.8kb2022-12-10 09:38:562022-12-10 09:38:57

Judging History

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

  • [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:38:57]
  • 评测
  • 测评结果:12
  • 用时:1346ms
  • 内存:3680kb
  • [2022-12-10 09:38:56]
  • 提交

answer

#include <bits/stdc++.h>
#define ll unsigned 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;
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);
    }
    mm=fast_pow(4,ph-1,P);
}



int ask (long long 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++){
        ll M=P/A[i],T=INV(M,A[i]);
        ans=(ans+B[i]*M%P*T%P)%P;
    }
    ans=ans*n%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 ans;
}

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: 16ms
memory: 3268kb

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: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #13:

score: 8
Accepted
time: 1ms
memory: 3320kb

input:

7 1 731039
314313205082038759

output:

0

result:

ok 1 number(s): "0"

Test #14:

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

input:

7 1 587945
675184352277027016

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 29ms
memory: 3352kb

input:

7 1 732151
522404464427087971

output:

0

result:

ok 1 number(s): "0"

Test #16:

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

input:

7 1 952025
865782493150981281

output:

0

result:

ok 1 number(s): "0"

Test #17:

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

input:

7 1 151005
80048698775676684

output:

0

result:

ok 1 number(s): "0"

Test #18:

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

input:

7 1 819153
214538328031265195

output:

0

result:

ok 1 number(s): "0"

Test #19:

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

input:

7 1 84501
605460166753167761

output:

0

result:

ok 1 number(s): "0"

Test #20:

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

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: 3348kb

input:

7 1 629595
216539117331686464

output:

0

result:

ok 1 number(s): "0"

Test #23:

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

input:

7 1 317005
831315176686118434

output:

0

result:

ok 1 number(s): "0"

Test #24:

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

input:

7 1 204399
934354294367869212

output:

0

result:

ok 1 number(s): "0"

Test #25:

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

input:

7 1 98233
515248809013032256

output:

0

result:

ok 1 number(s): "0"

Test #26:

score: -8
Wrong Answer
time: 0ms
memory: 3276kb

input:

7 1 738315
930635383520033839

output:

607226

result:

wrong answer 1st numbers differ - expected: '51840', found: '607226'

Subtask #8:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 1346ms
memory: 3680kb

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
113
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
220
0
0
0
0
0
0
0
0
0
0
0
0
0
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: '113'

Subtask #9:

score: 0
Skipped

Dependency #2:

0%