次方快速幂
#include<iostream>
using namespace std;
int main() {int a, b, c, ans = 1;cin >> a >> b >> c;while(b) {if(b & 1) ans = (ans * a) % c;a = (a * a) % c;b >>= 1;}cout << ans % c << endl;return 0;
}
乘法取模
#include<iostream>
using namespace std;
int main() {int a, b, c, ans = 0;cin >> a >> b >> c;while(b) {if(b & 1) ans = (ans + a) % c;a = (a * a) % c;b >>= 1;}cout << ans % c <<endl;return 0;
}