1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll quick_pow(ll x, ll y, ll c) { 5 ll ans = 1; 6 while (y) { 7 if (y & 1) { 8 ans = (ans % c * x % c) % c; 9 } 10 x = (x % c * x % c) % c; 11 y >>= 1; 12 } 13 return ans; 14 } 15 int main() { 16 ll x, y, p; 17 while (cin >> x >> y >> p) { 18 ll ans = quick_pow(x, y, p); 19 cout << ans << endl; 20 } 21 return 0; 22 }
100分代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll quick_pow(ll x, ll y, ll c) { 5 ll ans = 1; 6 while (y) { 7 if (y & 1) { 8 ans = (ans % c * x % c) % c; 9 } 10 x = (x % c * x % c) % c; 11 y >>= 1; 12 } 13 return ans; 14 } 15 int main() { 16 ll x, y, p; 17 while (cin >> x >> y >> p) { 18 ll ans = quick_pow(x % p, y, p); 19 cout << ans << endl; 20 } 21 return 0; 22 }
找不同系列
原文:https://www.cnblogs.com/fx1998/p/12722077.html