#include<iostream>
using namespace std;
typedef long long ll;
int main(){
ll a,b,p,ans=0;
cin>>a>>b>>p;
while(b){
if(b&1) ans=(ans+a)%p;
b>>=1;
a=a*2%p;
}
cout<<ans<<"
";
return 0;
}
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
ll a,b,p,ans=0;
cin>>a>>b>>p;
while(b){
if(b&1) ans=(ans+a)%p;
b>>=1;
a=a*2%p;
}
cout<<ans<<"
";
return 0;
}