You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
378 B
21 lines
378 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
// 龟速乘
|
|
int gui(int a, int b, int p) {
|
|
int res = 0;
|
|
while (b) {
|
|
if (b & 1) res = (res + a) % p;
|
|
a = (a + a) % p;
|
|
b >>= 1;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
int main() {
|
|
int a, b, p;
|
|
cin >> a >> b >> p;
|
|
printf("%lld\n", gui(a, b, p));
|
|
return 0;
|
|
}
|