[AcWing 90] 64位整数乘法
位运算
大数乘法
点击查看代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e5 + 10;
LL a, b, p;
void solve()
{
cin >> a >> b >> p;
LL res = 0;
while (b) {
if (b & 1)
res = (res + a) % p;
b >>= 1;
a = (a + a) % p;
}
cout << res << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}
- 类比快速幂,位运算做乘法