题解 | #快速乘#
快速乘
http://www.nowcoder.com/practice/043c66e95fe548d0b8e56c1830330f93
#include<iostream>
#define MOD 2e+7
using namespace std;
int main()
{
long long int q,a,b,p;
cin >> q;
while(q--){
cin >> a >> b >> p;
long long int index = b,base = a,ans = 0;
while(index){
if(index % 2 != 0)
ans = (ans + base) % p;
base = base + base;
base = base % p;
index /= 2;
}
cout << ans << endl;
}
}