#include <iostream>
using namespace std;
typedef unsigned long long ull;
int main(void)
{
ull a,b,p,sum = 0;
scanf("%lld%lld%lld",&a,&b,&p);
while (b)
{
if (b & 1) sum = (sum + a) % p;
a = a * 2 % p;
b >>= 1;
}
printf("%lld",sum);
return 0;
}