龟速乘 O(logn)
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define de(x) cout<<#x<<" = "<<x<<" "
#define deg(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int N=10010,M=10010;
typedef pair<int,int> PII;
int qadd(int a,int b,int p)
{
int res=0;
while(b)
{
if(b&1)res=(res+a)%p;
a=(a+a)%p;
b>>=1;
}
return res;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a,b,p;
cin>>a>>b>>p;
cout<<qadd(a,b,p)<<endl;
return 0;
}