miller_rabin

奇妙算法。快速判大质数的奇怪算法。

code:

inline bool check(int wh){
	if(wh%2==0)return false;
	int p=wh-1,q=1;
	while(p%2==0)p/=2,q++;
	for(int i=1;i<=K;i++){
		int x=rand()+1,last=1;
		if(qpow(x,wh-1,wh)!=1)return false;
		for(int j=0;j<q;j++){
			int t=qpow(x,(1ll<<j)*p,wh);
			if(t==1&&last!=1&&last!=wh-1)return false;
			last=t;
		}
		if(last!=1&&last!=wh-1)return false;
	}
	return true;
}
posted @ 2022-09-06 19:40  Feyn618  阅读(14)  评论(0编辑  收藏  举报