![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <iostream> 2 using namespace std; 3 long long fastm(long long a, long long b, long long p) 4 { 5 long long ans = 1; 6 a = a%p; 7 while(b) 8 { 9 if(b%2 == 1) 10 { 11 ans = ans*a; 12 ans = ans%p; 13 } 14 a = a*a; 15 a = a%p; 16 b = b/2; 17 } 18 return ans%p; 19 } 20 int main() 21 { 22 long long a, b, c; 23 cin >> a>> b >> c; 24 cout << fastm(a, b, c) << endl; 25 }