题解 | #快速乘#
快速乘
https://www.nowcoder.com/practice/043c66e95fe548d0b8e56c1830330f93
//和上一题几乎一模一样,只不过把*换成+ //同时base初值为0 #include <iostream> using namespace std; int main() { int q; cin>>q; long long a, b, p; long long base; for(int i=0;i<q;++i){ cin>>a>>b>>p; base = 0; while(b){ if(b%2!=0){ base = base + a; } base = base % p; a += a; a = a%p; b /= 2; } cout<<base<<endl; } } //