#include <iostream>
using namespace std;
int main() {
long long a, b, p;
cin >> a >> b >> p;
a %= p, b %= p;
long long temp = a, ans = 0;
for (; b ; b >>= 1) {
if (b & 1) ans = (ans + temp) % p;
temp = (temp + temp) % p;
}
cout << ans % p << endl;
}