#include <iostream>
using namespace std;
typedef unsigned long long ull;
ull q(ull a, ull b, ull p)
{
ull res = 0 ;
while(b)
{
if (b & 1) res = (res + a) %p;
a = a * 2 % p;
b >>= 1;
}
return res;
}
int main()
{
ull a, b, p;
cin >> a >> b >> p;
cout << q(a, b, p) << endl;
return 0;
}
因为 a * 20 = 2
a * 21 = 2a
a * 22 = 4a
…
所以可得 a = a * 2
Acwing 中的89更次类似只不过89是以 a次方的2的i次方(i为0,1,2,3,4,5…)且后者是前者的平方