模重复平方运算

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Whomio/article/details/79352452
#include<stdio.h>
//模重复平方运算
int qe2(int x,int y,int m)
{
	int a=1,b=x,n=y;
	while(n){
		if(n&1)
			a=(a*b)%m;
		b=(b*b)%m;
		n>>=1;
	}
	return a;
}

int main()
{
	printf("Please input Base,Index,Mold\n");
	int a,e,m;
	while(scanf("%d%d%d",&a,&e,&m)!=-1)
		printf("%d\n",qe2(a,e,m));
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Whomio/article/details/79352452