0
点赞
收藏
分享

微信扫一扫

算法竞赛进阶指南:0x01位运算:64位整数乘法(快速乘)

先峰老师 2022-03-18 阅读 78
c++算法

题目位置https://www.acwing.com/problem/content/92/

#include<iostream>
using namespace std;

typedef long long LL;

int main()
{
	LL a,b,p;
	cin>>a>>b>>p;
	
	LL ans=0;
	while(b)
	{
		if(b&1)ans=(ans+a)%p;
		a=a*2%p;
		b>>=1;
	}
	cout<<ans<<endl;
	
	return 0;
}

 

举报

相关推荐

0 条评论