QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#817287 | #4166. 古代猪文 | SGColin | 100 ✓ | 2ms | 4252kb | C++20 | 1.1kb | 2024-12-16 21:26:56 | 2024-12-16 21:26:57 |
Judging History
answer
#include<bits/stdc++.h>
#define N 50010
#define mo 999911658ll
using namespace std;
typedef long long ll;
ll mod[5]={0,2,3,4679,35617},m[5],fac[N];
inline void init(ll p){
fac[0]=1;
for(ll i=1;i<=p;++i) fac[i]=fac[i-1]*i%p;
}
inline ll qpow(ll x,ll t,ll p){
ll res=1;
while(t){
if(t&1) (res*=x)%=p;
(x*=x)%=p; t>>=1;
}
return res;
}
ll C(ll n,ll m,ll p){
if(m>n) return 0;
return fac[n]*qpow(fac[m],p-2,p)%p*qpow(fac[n-m],p-2,p)%p;
}
ll lucas(ll n,ll m,ll p){
if(n<m) return 0;
if(!m||!n) return 1;
return C(n%p,m%p,p)*lucas(n/p,m/p,p)%p;
}
inline ll solve(ll n,ll p){
init(p);
ll t=sqrt(n),res=0;
for(ll i=1;i<=t;++i)
if(n%i==0){
(res+=lucas(n,i,p))%=p;
if(n/i!=i) (res+=lucas(n,n/i,p))%=p;
}
return res;
}
inline ll CRT(ll n){
ll res=0;
for(ll i=1;i<=4;++i){
m[i]=mo/mod[i];
res=(res+m[i]*solve(n,mod[i])%mo*qpow(m[i],mod[i]-2,mod[i]))%mo;
}
return res;
}
int main(){
ll n,g;
scanf("%lld%lld",&n,&g);
if(g%(mo+1)==0){puts("0");return 0;}
printf("%lld\n",qpow(g,CRT(n),mo+1));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 0ms
memory: 4252kb
input:
24 227655187
output:
268407382
result:
ok single line: '268407382'
Test #2:
score: 5
Accepted
time: 1ms
memory: 4092kb
input:
48 162572551
output:
844226850
result:
ok single line: '844226850'
Test #3:
score: 5
Accepted
time: 1ms
memory: 4044kb
input:
420 156955809
output:
866130752
result:
ok single line: '866130752'
Test #4:
score: 5
Accepted
time: 1ms
memory: 4236kb
input:
984 175422269
output:
301639070
result:
ok single line: '301639070'
Test #5:
score: 5
Accepted
time: 1ms
memory: 4252kb
input:
15015 16515289
output:
955216017
result:
ok single line: '955216017'
Test #6:
score: 5
Accepted
time: 1ms
memory: 4108kb
input:
24633 806082456
output:
279303401
result:
ok single line: '279303401'
Test #7:
score: 5
Accepted
time: 1ms
memory: 4172kb
input:
52311 614403721
output:
711757654
result:
ok single line: '711757654'
Test #8:
score: 5
Accepted
time: 1ms
memory: 4176kb
input:
62370 34849907
output:
625045294
result:
ok single line: '625045294'
Test #9:
score: 5
Accepted
time: 0ms
memory: 4108kb
input:
753447601 45941770
output:
598569129
result:
ok single line: '598569129'
Test #10:
score: 5
Accepted
time: 1ms
memory: 4048kb
input:
945764054 242359537
output:
846078071
result:
ok single line: '846078071'
Test #11:
score: 5
Accepted
time: 0ms
memory: 4088kb
input:
945764058 295965211
output:
189097853
result:
ok single line: '189097853'
Test #12:
score: 5
Accepted
time: 0ms
memory: 4228kb
input:
945764146 174114001
output:
615490219
result:
ok single line: '615490219'
Test #13:
score: 5
Accepted
time: 1ms
memory: 4168kb
input:
223092870 378256627
output:
463324931
result:
ok single line: '463324931'
Test #14:
score: 5
Accepted
time: 0ms
memory: 4188kb
input:
248834355 266664277
output:
569037366
result:
ok single line: '569037366'
Test #15:
score: 5
Accepted
time: 1ms
memory: 4088kb
input:
746503065 188518317
output:
194042372
result:
ok single line: '194042372'
Test #16:
score: 5
Accepted
time: 1ms
memory: 4248kb
input:
386122275 139473405
output:
7561904
result:
ok single line: '7561904'
Test #17:
score: 5
Accepted
time: 1ms
memory: 4240kb
input:
900951975 90523153
output:
81793986
result:
ok single line: '81793986'
Test #18:
score: 5
Accepted
time: 1ms
memory: 4212kb
input:
797986035 866545121
output:
101524549
result:
ok single line: '101524549'
Test #19:
score: 5
Accepted
time: 2ms
memory: 4252kb
input:
669278610 398361241
output:
253531581
result:
ok single line: '253531581'
Test #20:
score: 5
Accepted
time: 0ms
memory: 3696kb
input:
999911657 999911659
output:
0
result:
ok single line: '0'