#include<stdio.h> typedef long long LL; LL binary_pow(int a,int b,int m) { LL ans = 1; while(b>0) { if(b&1) ans = ans*a%m; a = a*a%m; b>>=1;//右移一位 } return ans; } int main() { int x,y,z; scanf("%d%d%d",&x,&y,&z); printf("x的y次方模z的结果为:%d",binary_pow(x,y,z)); return 0; }
纯练习
原文:https://www.cnblogs.com/xhjj/p/12220212.html