#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;
///计算(x*y)mod z 的值
long long mul(long long x,long long y,long z)
{
long long ans=0;
while(y){
if(y&1){
ans=(ans+x)%z;
}
x=(x*2)%z;
y>>=1;
}
return ans;
}
int main()
{
long long a,b,p;
while(scanf("%lld%lld%lld",&a,&b,&p)!=EOF){
printf("%lld\n",mul(a,b,p));
}
return 0;
}