Hust oj 1521 Marshal's Confusion III(整数快速幂)
来源:互联网 发布:windows缩小图片大小 编辑:程序博客网 时间:2024/06/06 00:35
Marshal's Confusion IIITime Limit: 3000 MSMemory Limit: 65536 KTotal Submit: 282(71 users)Total Accepted: 89(60 users)Rating: Special Judge: NoDescriptionMarshallike to solve acm problems.But they are very busy, one day they meet a problem. Given three intergers a,b,c, the task is to compute a^(b^c))%317000011. so the turn to you for help. InputThe first line contains an integer T which stands for the number of test cases. Each case consists of three integer a, b, c seperated by a space in a single line. 1 <= a,b,c <= 100000OutputFor each case, print a^(b^c)%317000011 in a single line.Sample Input2
1 1 1
2 2 2Sample Output
1 1 1
2 2 2Sample Output
1
16
王勇
简单的整数快速幂,只不过从a^b mod c变成了a^b^c mod c,变形之后就是a^(b^c mod c-1)mod c,然后套模板
#include<iostream>#include<cstring>using namespace std;const int mod=317000011;long long quickpow(long long m , long long n , long long k){ long long int ans = 1; while(n){ if(n&1) ans = (ans * m) % k; n = n >> 1; m = (m * m) % k; } return ans;}int main(){ int n; long long int a,b,c; cin>>n; while(n--) { cin>>a>>b>>c; cout<<quickpow(a,quickpow(b,c,mod-1),mod)<<endl;; }}
0 0
- Hust oj 1521 Marshal's Confusion III(整数快速幂)
- Hust oj 1196 Marshal's confusion II(公式)
- HLG 1251 Marshal's Confusion III (快速幂)
- HRBUST 1251 Marshal's Confusion III 【快速幂】 (2013 3.13)
- 哈理工 1251 Marshal's Confusion III(太坑快速幂)
- HLG 1251 Marshal's Confusion III
- 哈理工OJ 1196 Marshal's confusion II(数学公式题)
- Hust oj 1953 RSA验证(快速幂)
- Hust oj 1053 Warcraft III(完全背包)
- Hust oj 2084(大数)
- Yuna's confusion
- Hust oj 2038 联系网络(MST)
- Hust oj 2234 土豪银行(贪心)
- Hust oj 1143 泉水(dfs)
- Hust oj 2113 Count(Map)
- Hust oj 1305 多边形(数学)
- Hust oj 1677 一个函数(栈)
- Hust oj 1039 修路(二分)
- UVA--1211(二分+前缀和)
- 关于NIS服务绑定和mount挂载的问题
- LeetCode--172. Factorial Trailing Zeroes
- 蓝桥杯 历届试题 振兴中华
- Toast的参数选择
- Hust oj 1521 Marshal's Confusion III(整数快速幂)
- CF 615 E Hexagons(找规律)
- 带参数的宏定义
- 感受HTML5 Audio API带来的视听盛宴
- F - 播放器
- Struts中的拦截器——登录验证实例
- 【小镇的技术天梯】cpu的基本原理
- java中方法的重载
- run loop