借助快速幂的思想,由平方转化为乘积
#include <iostream>
using namespace std;
int main()
{
long long a, b, p;
long long res = 0;
cin >> a >> b >> p;
while(b)
{
if(b & 1) res = (res + a) % p;
a = a * 2 % p;
b >>= 1;
}
cout << res % p << endl;
return 0;
}