POJ-1995 Raising Modulo Numbers---快速幂模板
题目链接:
https://vjudge.net/problem/POJ-1995
题目大意:
求一堆ab的和模上m
思路:
直接上模板
1 #include<iostream> 2 #include<vector> 3 #include<queue> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdio> 7 #include<set> 8 #include<cmath> 9 using namespace std; 10 typedef pair<int, int> Pair; 11 typedef long long ll; 12 const int INF = 0x3f3f3f3f; 13 const int maxn = 2000+10; 14 int T, n, m; 15 ll quick_pow(ll a, ll b, ll m) 16 { 17 a %= m; 18 ll ans = 1; 19 while(b) 20 { 21 if(b & 1)ans = ans * a % m; 22 b /= 2; 23 a *= a; 24 a %= m; 25 } 26 ans %= m; 27 return ans; 28 } 29 int main() 30 { 31 cin >> T; 32 while(T--) 33 { 34 cin >> m >> n; 35 ll sum = 0, a, b; 36 while(n--) 37 { 38 cin >> a >> b; 39 sum += quick_pow(a, b, m); 40 sum %= m; 41 } 42 cout<<sum<<endl; 43 } 44 }
越努力,越幸运