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 }

 

转载于:https://www.cnblogs.com/fzl194/p/8810070.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值