Raising Modulo Numbers POJ 1995(快速幂模板)

原题

题目链接

题目分析

快速幂模板题,依题意套个求模快速幂,然后答案边加边模即可.

代码

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <utility>
 6 #include <ctime>
 7 #include <cmath>
 8 #include <cstring>
 9 #include <string>
10 #include <stack>
11 #include <queue>
12 #include <vector>
13 #include <set>
14 #include <map>
15 
16 using namespace std;
17 typedef long long LL;
18 const int INF_INT=0x3f3f3f3f;
19 const LL INF_LL=0x3f3f3f3f3f3f3f3f;
20 
21 LL q_power(LL a,LL b,LL mod)
22 {
23     LL res=1;
24     a%=mod;
25     while(b)
26     {
27         if(b&1) res=(res*a)%mod;
28         a=(a*a)%mod;
29         b>>=1;
30     }
31     return res;
32 }
33 
34 int main()
35 {
36 //    freopen("black.in","r",stdin);
37 //    freopen("black.out","w",stdout);
38     int t;
39     scanf("%d",&t);
40     while(t--)
41     {
42         int m,h;
43         scanf("%d %d",&m,&h);
44         LL res=0;
45         for(int i=0;i<h;i++)
46         {
47             LL a,b;
48             scanf("%lld %lld",&a,&b);
49             res=(res+q_power(a,b,m))%m;
50         }
51         printf("%lld\n",res);
52     }
53     return 0;
54 }

 

转载于:https://www.cnblogs.com/VBEL/p/11444673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值