位运算-快速乘法

匿名 (未验证) 提交于 2019-12-03 00:27:02
#include<bits/stdc++.h>
using namespace std;
int a,b,p;
int mul(int x,int y){
int ans=0;
while(y){
if(y&1)ans=(ans+x)%p;
x=x*2%p;
y>>=1;
}
return ans;
}
int main(){
cin>>a>>b>>p;
cout<<mul(a,b);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!