SDNUOJ 1081 快速幂

Description
计算2013^b ^c mod 10000000
Input
两个整数 b, c (0 < b, c < 2147483648)
Output
输出2013bc mod 10000000的结果
Sample Input
2012 2011
Sample Output
3307281

算两次快速幂

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define mo 10000000

int main()
{
    int a = 2013;
    long long b, c;
    while(scanf("%lld%lld",&b, &c) != EOF)
    {
        long long d = a % mo;
        long long e = 1;
        while(b)
        {
            if(b % 2 == 1)
            {
                e = e * d % mo;
            }
            d = d * d % mo;
            b /= 2;
        }
        long long f = e % mo;
        long long g = 1;
        while(c)
        {
            if(c % 2 == 1)
            {
                g = g * f % mo;
            }
            f = f * f % mo;
            c /= 2;
        }
        cout << g % mo << '\n' ;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zhaobaole2018/article/details/84872746