QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#830780 | #1457. FFT Algorithm | Kazemaru | AC ✓ | 679ms | 3940kb | C++14 | 1.5kb | 2024-12-24 22:44:34 | 2024-12-24 22:44:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
__int128 _=1;int mo;
#define vi vector<int>
mt19937_64 rd(time(NULL)+37);
inline int rnd(int l,int r){;return rd()%(r-l+1)+l;}
inline int ksm(int x,int p,int mo,int y=1){for(;p;p/=2,x=_*x*x%mo)if(p&1)y=_*x*y%mo;return y;}
inline int pd(int a,int p){
int r=0,k=p-1,l=p-1;
for(;k&1^1;k>>=1)++r;
for(a=ksm(a,k,p);r--&&a!=1;a=_*a*a%p)l=a;
return a==1&&l+1==p;
}
inline int ip(int x){if(x<3)return x==2;f(i,1,40)if(!pd(rnd(2,x-1),x))return 0;return 1;}
inline int PR(int x){
int a,b,c=rnd(1,x-1),d,e=127,s,t=0;
for(a=1;a<=x;a<<=1){
s=t;b=1;
f(r,1,a){
t=(_*t*t+c)%x;
if(s==t)return (d=__gcd(b,x))>1?d:PR(x);
b=_*b*abs(t-s)%x;
if(!(r&e)&&(d=__gcd(b,x))>1)return d;
}
if((d=__gcd(b,x))>1)return d;
}
return PR(x);
}
vi fj(int x){
if(x<2)return{};
if(ip(x))return{x};
int p=PR(x),q=0;
for(;x%p==0;x/=p)++q;
vi a=fj(x),b=fj(p);
f(_,1,q)for(int y:b)a.push_back(y);
return a;
}
vi w;
int ask(int x){
int z=m;
for(int p:w)for(;z%p==0&&ksm(x,z/p,mo)==1;z/=p);
return __gcd(x,mo)>1?1:z;
}
#define uq(a)sort(a.begin(),a.end());a.erase(unique(a.begin(),a.end()),a.end())
signed main(){
cin>>m>>n;mo=m;
w=fj(m);uq(w);
for(int p:w)m=m/p*(p-1);
w=fj(m);uq(w);
s=1<<n;
f(i,1,1e5)if((l=ask(i))%s==0){
cout<<ksm(i,l/s,mo);exit(0);
}
cout<<-1;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3904kb
input:
998244353 23
output:
15311432
result:
ok OK valid solution
Test #2:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
1048576 15
output:
6561
result:
ok OK valid solution
Test #3:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
3 23
output:
-1
result:
ok OK no solution
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
997261313 15
output:
365254143
result:
ok OK valid solution
Test #5:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
971604167 15
output:
693649921
result:
ok OK valid solution
Test #6:
score: 0
Accepted
time: 185ms
memory: 3680kb
input:
561972416 15
output:
-1
result:
ok OK no solution
Test #7:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
998572034 15
output:
739803799
result:
ok OK valid solution
Test #8:
score: 0
Accepted
time: 203ms
memory: 3640kb
input:
127941919 15
output:
-1
result:
ok OK no solution
Test #9:
score: 0
Accepted
time: 215ms
memory: 3912kb
input:
945553409 15
output:
-1
result:
ok OK no solution
Test #10:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
998244353 23
output:
15311432
result:
ok OK valid solution
Test #11:
score: 0
Accepted
time: 156ms
memory: 3688kb
input:
596468390 23
output:
-1
result:
ok OK no solution
Test #12:
score: 0
Accepted
time: 108ms
memory: 3668kb
input:
813335261 23
output:
-1
result:
ok OK no solution
Test #13:
score: 0
Accepted
time: 114ms
memory: 3672kb
input:
293185311 23
output:
-1
result:
ok OK no solution
Test #14:
score: 0
Accepted
time: 196ms
memory: 3704kb
input:
431142105 23
output:
-1
result:
ok OK no solution
Test #15:
score: 0
Accepted
time: 209ms
memory: 3676kb
input:
545259521 23
output:
-1
result:
ok OK no solution
Test #16:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
999999998361601 15
output:
596739826094319
result:
ok OK valid solution
Test #17:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
999956339174017 15
output:
831437096353390
result:
ok OK valid solution
Test #18:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
999999934158041 15
output:
478047879184688
result:
ok OK valid solution
Test #19:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
999870494845507 15
output:
824076331860218
result:
ok OK valid solution
Test #20:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
987500017287169 15
output:
728983403990856
result:
ok OK valid solution
Test #21:
score: 0
Accepted
time: 269ms
memory: 3668kb
input:
999869489774593 15
output:
-1
result:
ok OK no solution
Test #22:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
999999643058177 23
output:
375603868068691
result:
ok OK valid solution
Test #23:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
999029131455133 23
output:
597546885368399
result:
ok OK valid solution
Test #24:
score: 0
Accepted
time: 339ms
memory: 3844kb
input:
980573759207039 23
output:
-1
result:
ok OK no solution
Test #25:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
997380719651467 23
output:
894679229693756
result:
ok OK valid solution
Test #26:
score: 0
Accepted
time: 679ms
memory: 3748kb
input:
673383102728611 23
output:
-1
result:
ok OK no solution
Test #27:
score: 0
Accepted
time: 446ms
memory: 3708kb
input:
997055929516033 23
output:
-1
result:
ok OK no solution
Test #28:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
3999999999999705089 15
output:
1058625960373983012
result:
ok OK valid solution
Test #29:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
3999993153100322407 15
output:
1684293148309090316
result:
ok OK valid solution
Test #30:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
3999999979069450717 15
output:
3418373025234552474
result:
ok OK valid solution
Test #31:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3999991341703927187 15
output:
3809043281050504927
result:
ok OK valid solution
Test #32:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
1641566238888296449 15
output:
391907170255173830
result:
ok OK valid solution
Test #33:
score: 0
Accepted
time: 446ms
memory: 3900kb
input:
3999987196009414657 15
output:
-1
result:
ok OK no solution
Test #34:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
3999999999713738753 23
output:
2541755635409224047
result:
ok OK valid solution
Test #35:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
3999977144498948549 23
output:
858148666025926742
result:
ok OK valid solution
Test #36:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
3999999983264930527 23
output:
3446137548938641420
result:
ok OK valid solution
Test #37:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
3999867163212679501 23
output:
2122614505987985292
result:
ok OK valid solution
Test #38:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2928465661120217089 23
output:
2784037196602552280
result:
ok OK valid solution
Test #39:
score: 0
Accepted
time: 565ms
memory: 3608kb
input:
3999790589313810433 23
output:
-1
result:
ok OK no solution
Test #40:
score: 0
Accepted
time: 33ms
memory: 3908kb
input:
65536 15
output:
-1
result:
ok OK no solution
Test #41:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
131072 15
output:
3
result:
ok OK valid solution
Test #42:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
2305843009213693952 15
output:
1049127606944792577
result:
ok OK valid solution
Test #43:
score: 0
Accepted
time: 48ms
memory: 3664kb
input:
16777216 23
output:
-1
result:
ok OK no solution
Test #44:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
33554432 23
output:
3
result:
ok OK valid solution
Test #45:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2305843009213693952 23
output:
661623700310720513
result:
ok OK valid solution