#include <iostream>
#define Ull unsigned long long
using namespace std;
Ull quickMul( Ull a, Ull b, Ull p )
{
Ull res=0, base=b;
while ( a )
{
if ( a & 1 ) res = (res+base)%p;
base = (base+base)%p;
a >>= 1;
}
return res;
}
int main()
{
Ull a, b, p, s;
cin >> a >> b >> p;
s = quickMul(a, b, p);
cout << s << endl;
return 0;
}