点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll a,b,p;
ll solve()
{
ll ans=0;
while(b)
{
if(b&1)
ans=(ans+a)%p;
b=b>>1;
a=(a<<1)%p;
}
return ans%p;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>a>>b;
cin>>p;
cout<<solve()<<endl;
return 0 ^ 0;
}