【快速幂】AcWing875.快速幂——模板题

2022/6/9 23:22:49

本文主要是介绍【快速幂】AcWing875.快速幂——模板题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

AcWing875.快速幂

题解

#include <iostream>

using namespace std;

typedef long long LL;

int main()
{
    int n, a, b, p;
    cin >> n;
    
    while(n -- )
    {
        int res = 1;
        cin >> a >> b >> p;
        while(b)
        {
            if(b & 1) res = res * (LL)a % p;
            b >>= 1;
            a = a * (LL)a % p;
        }
        cout << res << endl;
    }
    return 0;
}


这篇关于【快速幂】AcWing875.快速幂——模板题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程