QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67759 | #5099. 朝圣道 | OvO_Zuo | 0 | 3065ms | 27448kb | C++14 | 2.2kb | 2022-12-11 22:03:00 | 2022-12-11 22:03:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1000005;
typedef long long ll;
int mo;
ll n,m;
ll p_cnt[25],p_num[25];
int cnt=0;
int phi[25][N],ni[25][N];
void exgcd(int a,int b,ll &x,ll &y)
{
if(b==0)
{
x=1,y=0;
return;
}
exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
ll mi(ll x,ll y,ll p)
{
ll res=1;
// x%=p,y%=p;
for(;y;y>>=1,x=1ll*x*x%p)
if(y&1) res=1ll*res*x%p;
return res;
}
void div_p(int p)
{
int i,j;
ll x,y;
for(i=2;i<=p;i++)
{
if(p%i) continue;
p_num[++cnt]=i,p_cnt[cnt]=1;
while(p%i==0) p/=i,p_cnt[cnt]*=i;
phi[cnt][0]=1;
ni[cnt][0]=1;
// cout<<"yin "<<i<<endl;
for(j=1;j<=p_cnt[cnt];j++)
{
// cout<<j<<" ";
if(j%p_num[cnt]==0)
{
phi[cnt][j]=phi[cnt][j-1];
ni[cnt][j]=-1;
}
else
{
// cout<<phi[cnt][j-1]*j<<endl;
phi[cnt][j]=1ll*phi[cnt][j-1]*j%p_cnt[cnt];
exgcd(j,p_cnt[cnt],x,y);
if(x<0) x+=p_cnt[cnt];
ni[cnt][j]=x;
}
// cout<<"yiny "<<j<<" "<<ni[cnt][j]<<endl;
}
if(p==1)
{
cout<<"";
return;
}
}
cout<<"";
}
ll f(int lei,ll v)
{
if(v<=p_num[lei]) return phi[lei][v];
// cout<<lei<<" "<<v<<" "<<cal_ji(lei,v)<<endl;
return 1ll*((v/p_cnt[lei])&1?p_cnt[lei]-phi[lei][v%p_cnt[lei]]:phi[lei][v%p_cnt[lei]])*f(lei,v/p_num[lei])%p_cnt[lei];
}
//ll xi[N];
int calc(ll x,ll y)
{
ll i,j,a,b,t,ans=0;
// cout<<x<<" "<<y<<endl;
for(i=1;i<=cnt;i++)
{
a=f(i,x)*ni[i][f(i,y)]*ni[i][f(i,x-y)]%p_cnt[i];
for(j=x;j;j/=mo) t+=j/mo;
for(j=y;j;j/=mo) t-=j/mo;
for(j=x-y;j;j/=mo) t-=j/mo;
// t=get_vp(i,x)-get_vp(i,y)-get_vp(i,x-y);
b=mi(p_num[i],t,p_cnt[i]);
ans=(ans+1ll*a*b%p_cnt[i]*(mo/p_cnt[i])%mo*ni[i][mo/p_cnt[i]]%mo)%mo;
}
// ll xx,yy,ans=0,tm;
// for(i=1;i<=cnt;i++)
// {
// tm=mo/p_cnt[i];
// exgcd(tm,p_cnt[i],xx,yy);
// if(xx<0) xx+=p_cnt[i];
// ans=(ans+xi[i]*tm*xx%mo);
// }
return ans%mo;
}
int er[N],er_ni[N],mod;
void init (int o, int p)
{
mo=p;
div_p(p);
int i,j;
er[0]=er_ni[0]=1;
er_ni[1]=(mo+1)/2;
for(i=1;i<=N-5;i++)
{
er[i]=er[i-1]*2%mo;
er_ni[i]=1ll*er_ni[i-1]*er_ni[1]%mo;
if(er[i]==1) mod=i;
}
}
int ask (long long n)
{
return 1ll*calc(2*n,n)*er_ni[2*n%mod]%mo*(n%mo)%mo;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 450ms
memory: 23568kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1st numbers differ - expected: '5419', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 55ms
memory: 21780kb
input:
3 1 334547 8234
output:
0
result:
wrong answer 1st numbers differ - expected: '179079', found: '0'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 3065ms
memory: 27448kb
input:
6 958477 522361 280121915553826833 734266539148641647 72849162479700582 274266741463686096 60278972064195458 828423669427600612 571432949203039978 518511460268700898 486268614705621285 19216283231217074 611458416727512530 175147354285288662 799769622289998997 400123443628688299 145546980862133838 40...
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 12th numbers differ - expected: '193620', found: '0'
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 31ms
memory: 19752kb
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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: '0'
Subtask #9:
score: 0
Skipped
Dependency #2:
0%