题解 | #快速乘#
快速乘
https://www.nowcoder.com/practice/043c66e95fe548d0b8e56c1830330f93
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int qmul(int a, int b, int p){
LL res = 0;
while(b){
if(b & 1) res = (LL)(res + a) % p;
b >>= 1;
a = (a + a) % p;
}
return res;
}
int main() {
int q;
cin >> q;
while(q --){
int a, b, p;
cin >> a >> b >> p;
cout << qmul(a, b, p) << endl;
}
return 0;
}
