标签:lib cout iostream long eps ack open its dog
入门的快速幂 要注意的是x^p的范围没给 用int会爆 最保险的 还是用long long
/*
author:hdsdogge
begin:
end:
cost:
*/
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<list>
#include <sstream>
#include<ctype.h>
using namespace std;
const int maxn=100+10;
typedef pair<int,int> P;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
int T,n,m,M;
ll a,b;
int main() {
//freopen("test","r",stdin);
//freopen("out","w",stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin>>T;
while(T--){
cin>>M;
cin>>n;
ll sum=0;
for(int i=0;i<n;i++){
cin>>a>>b;
ll x=a;
ll p=b;
ll ans=1;
while(p>0){
if(p&1) ans=ans*x%M;
x=x*x%M;
p>>=1;
}
sum+=ans;
}
cout<<sum%M<<endl;
}
return 0;
}
Raising Modulo Numbers POJ - 1995
标签:lib cout iostream long eps ack open its dog
原文地址:https://www.cnblogs.com/hdsdogge/p/9349795.html