题解 | #快速乘#

快速乘

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;
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务