题目地址


注意点:

  • p也要开long long.

#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
ll p;
ll mull(ll a,ll b){
	ll ans=0,tmp=a;
	while(b){
		if(b&1)ans=(ans+tmp)%p;
		tmp=(tmp+tmp)%p;
		b>>=1;
	}
	return ans;
}
int main(){
	ll a,b;
	scanf("%lld%lld%lld",&a,&b,&p);
	ll ans=mull(a,b);
	printf("%lld\n",ans);
	return 0;
}