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