多学习。

【快速幂】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;
}
posted @ 2022-06-09 21:30  czyaaa  阅读(30)  评论(0)    收藏  举报