AW90 64位整数乘法

题目地址


注意点:

  • 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
",ans);
	return 0;
}

  

原文地址:https://www.cnblogs.com/zbsy-wwx/p/11735007.html