HLG-1251(快速幂)

来源:互联网 发布:查看linux开机启动项 编辑:程序博客网 时间:2024/05/18 01:17
Marshal's Confusion III
Time Limit: 3000 MS    Memory Limit: 65536 K
Description
Marshallike 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.
Input
The 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 <= 100000
Output
For each case, print a^(b^c)%317000011 in a single line.
Sample Input
2
1 1 1
2 2 2
Sample Output
1

16

//求a^b^c%317000011#include<iostream>using namespace std;int main(){long long int n;long long int a,b,c;cin>>n;while(n--){cin>>a>>b>>c;long long int sum=1;while(c--){    long long int s=a;sum=1;    int k=b;           while(k)        {if(k&1){sum=sum*s%317000011;}s=s*s%317000011;k>>=1;        }   a=sum;}cout<<sum<<endl;}return 0;}


0 0
原创粉丝点击