模重复平方运算

2019-04-13 11:59发布

#include //模重复平方运算 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 "); int a,e,m; while(scanf("%d%d%d",&a,&e,&m)!=-1) printf("%d ",qe2(a,e,m)); return 0; }