P1226-快速幂
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define _for(i,a,b) for(int i = (a);i < b;i ++) 4 typedef long long ll; 5 6 ll mi(ll a,ll b,ll m) 7 { 8 if(!b) 9 10 return (ll)0; 11 12 ll rnt = 1; 13 while(b>0) 14 15 { 16 if(b&0x1) 17 18 rnt=(rnt*a)%m; 19 a = (a*a)%m; 20 b >>= 1; 21 } 22 return rnt; 23 } 24 int main() 25 { 26 ll a,b,m; 27 28 scanf("%lld%lld%lld",&a,&b,&m); 29 30 printf("%lld^%lld mod %lld=%lld\n",a,b,m,mi(a,b,m)); 31 32 return 0; 33 }