poj1995 Raising Modulo Numbers (快速幂,挑战有模版,纪念一下A的第一道快速幂)

/*快速幂,时间复杂度,数据范围*/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
long long a, b;
int n, m;
int sum, res;
typedef long long ll;

ll mod_pow(ll x, ll y, int z)
{
    res = 1;
    while(y > 0){
        if(y & 1)
            res = res * x % z;
        x = x * x % z;
        y >>= 1;
    }
    return res;
}

int main()
{
    int t;
    scanf("%d", &t);
    while(t--){
        sum = 0;
        scanf("%d%d", &m, &n);
        for(int i = 0; i < n; i++){
            scanf("%l64d%l64d", &a, &b);
            sum = (sum + mod_pow(a, b, m)) % m;
        }
       printf("%d
", sum);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Joe962850924/p/4297101.html