QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67125 | #5099. 朝圣道 | aoui | 20 | 1370ms | 3552kb | C++14 | 2.8kb | 2022-12-10 09:41:53 | 2022-12-10 09:42:32 |
Judging History
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=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 ans;
}
詳細信息
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: 3256kb
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: 3272kb
input:
7 1 731039 314313205082038759
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
7 1 587945 675184352277027016
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 30ms
memory: 3272kb
input:
7 1 732151 522404464427087971
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3272kb
input:
7 1 952025 865782493150981281
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 5ms
memory: 3480kb
input:
7 1 151005 80048698775676684
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 4ms
memory: 3260kb
input:
7 1 819153 214538328031265195
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3200kb
input:
7 1 84501 605460166753167761
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 3ms
memory: 3260kb
input:
7 1 579977 434091105518396762
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
7 1 161075 649828935660369724
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 2ms
memory: 3312kb
input:
7 1 629595 216539117331686464
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3356kb
input:
7 1 317005 831315176686118434
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 3ms
memory: 3316kb
input:
7 1 204399 934354294367869212
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: 0
Accepted
time: 4ms
memory: 3356kb
input:
7 1 98233 515248809013032256
output:
0
result:
ok 1 number(s): "0"
Test #26:
score: 0
Accepted
time: 3ms
memory: 3416kb
input:
7 1 738315 930635383520033839
output:
51840
result:
ok 1 number(s): "51840"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3360kb
input:
7 1 404535 557582195171952455
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 3ms
memory: 3312kb
input:
7 1 277475 413241759909529359
output:
0
result:
ok 1 number(s): "0"
Test #29:
score: 0
Accepted
time: 3ms
memory: 3316kb
input:
7 1 206409 381910309127041513
output:
0
result:
ok 1 number(s): "0"
Test #30:
score: 0
Accepted
time: 162ms
memory: 3356kb
input:
7 1 694649 641706538274033333
output:
0
result:
ok 1 number(s): "0"
Test #31:
score: 0
Accepted
time: 50ms
memory: 3352kb
input:
7 1 974065 700551256691343002
output:
0
result:
ok 1 number(s): "0"
Test #32:
score: 0
Accepted
time: 3ms
memory: 3356kb
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: 1370ms
memory: 3552kb
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%