原根
1. 阶
设
成立的,称为
所以
同理
又因为
所以
2. 原根
若
则称
易知
严谨的数学证明推荐神仙sola的数学笔记
2.1. 求m 的原根
可证
一个想法是枚举
但是我们有
设
只用枚举
即:
对于
时,
bool check(long long gg,long long xx){
if(llgcd(gg,xx)>1) return false;
if(qpow(gg,phi[xx],xx)!=1) return false;
desol(phi[xx]);
for(int i=1;i<=fcnt;i++)
if(qpow(gg,phi[xx]/fac[i],xx)==1) return false;
return true;
}
long long calcprtg(long long x){
if(x<=4ll) return max(1ll,x-1);
if(!leg[x]) return 0;
for(int i=1;i<x;i++)
if(check(i,x)) return i;
return -1;
}
最后这个return -1;是用于查错的
若
都为
模板 LuoguP6091
int main(){
eulersieve();
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&N,&D);
gcnt=0;
g[++gcnt]=calcprtg(N);
if(g[1]==0){
puts("0\n");
continue;
}
if(g[1]==-1){
puts("Fuxk you!");
continue;
}
long long gg=g[1];
for(int i=2;i<phi[N];i++){
gg=(gg*g[1])%N;
if(llgcd(i,phi[N])==1)
g[++gcnt]=gg;
}
sort(g+1,g+gcnt+1);
printf("%lld\n",gcnt);
for(int i=D;i<=gcnt;i+=D)
printf("%lld ",g[i]);
puts("");
}
return 0;
}