HRBUST 1251 Marshal's Confusion III 【快速幂】 (2013 3.13)

Marshal's Confusion III
Time Limit: 3000 MS Memory Limit: 65536 K
    Rating:  Special Judge: No
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

Author
王勇

分析:
         快速幂模板,只不过是a^b^c  ,稍微修改一下就OK啦~~~

#include<iostream>
#include<string.h>
#define m 317000011
using namespace std;
int main()
{
    long long  res,tmp,a,b,c; int n;
    cin>>n;

    while(n--)
    {
        cin >> a>> b >> c;
        res=1;

        while(c--)
        {
            tmp = b;res = 1;

            while(tmp)
            {
                if(tmp & 1)
                res = ((a%m)*(res%m))%m;
                a = ((a%m)*(a%m))%m;
                tmp >>= 1;
            }
            a = res;
        }
        cout<<a<<endl;
    }
    return 0;
}

结果:
         
60612 1251 Accepted G++ 716ms 1128k A smile that I would never see again ! 556B 2013-03-13 00:04:34

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值