#include<iostream>
using namespace std;
typedef unsigned long long ULL;
ULL ANS(ULL a,ULL b,ULL p){
a%=p;b%=p;
ULL c = (long double)a*b/p;
//cout<<a<<b<<endl;
ULL x = a*b-p,y = c*p-p;
//cout<<x<<" "<<y<<endl;
long long ans = (long long)(x%p) - (long long)(y%p);
if(ans<0) ans+=p;
return ans;
}
int main(){
ULL a,b,p;
scanf("%llu%llu%llu",&a,&b,&p);
cout<<ANS(a,b,p)<<endl;
return 0;
}