#include<iostream>
#include<cstdio>
using namespace std;
long long a,b,p;
unsigned long long ans;
unsigned long long m(long long a2,long long b2,long long p2)
{
unsigned long long ans2=0,t=a2;
while(b2>0)
{
if(b2%2==1)
{
ans2=(ans2+t)%p2;
}
b2=b2/2;
t=(t+t)%p2;
}
return ans2;
}
int main()
{
freopen("64mul.in","r",stdin);
freopen("64mul.out","w",stdout);
scanf("%ld%ld%ld",&a,&b,&p);
ans=m(a,b,p);
printf("%ld",ans);
return 0;
}