Home | Problems | Discuss | Login

  

不能提交我就把代码贴这了

1493: Big Mod

126326481 | 2018-05-10 22:47:25 | delete | edit
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int pow_mod(int a,int n,int m){
	if(n==0)return 1;
	int x=pow_mod(a,n/2,m);
	long long ans=(long long)x*x%m;
	if(n%2==1)ans=ans*a%m;
	return (int)ans;
}



int main() {
	int B,P,M;
	while(~scanf("%d%d%d",&B,&P,&M)){
		printf("%d\n",pow_mod(B,P,M));
	}
	return 0;
}
 

Please login to reply.