51nod 1662 构造模函数

题目
看了代码就知道怎么做了。。。

#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7;
int k,p,s,m;
int pw(int x,int y){
	int z=1;
	for (;y;y>>=1,x=1ll*x*x%M)
		if (y&1) z=1ll*z*x%M;
	return z;
}
int main(){
	scanf("%d%d",&p,&k);
	if (k<2) printf("%d",pw(p,p-1+k));
	else{
		for (s=k;s!=1;s=1ll*s*k%p,m++);
		printf("%d",pw(p,(p-1)/(m+1)));
	}
}

猜你喜欢

转载自blog.csdn.net/xumingyang0/article/details/85119562