安全密码
题目链接:SSL 2237
题目大意
求 a^b mod c。
思路
直接上快速幂。
(虽然一个一个乘也可以过)
代码
#include<cstdio>
#define ll long long
using namespace std;
ll a, b, c;
ll ksm(ll a, ll b, ll mo) {
a %= mo;
ll re = 1;
while (b) {
if (b & 1) re = (re * a) % mo;
a = (a * a) % mo;
b >>= 1;
}
return re;
}
int main() {
// freopen("password.in", "r", stdin);
// freopen("password.out", "w", stdout);
scanf("%lld %lld %lld", &a, &b, &c);
printf("%lld", ksm(a, b, c));
fclose(stdin);
fclose(stdout);
return 0;
}