Key Set---hud5363(快速幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5363

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring>
using namespace std;
#define Mod 1000000007
long long Pow(int x, int n)
{
    if( n==1 )
        return x;
    long long d = Pow(x, n/2)%Mod;

    if(n%2==0)
        return (d * d)%Mod;
    else
        return (x * d * d)%Mod;

}

int main()
{
    int n, a;
    scanf("%d", &n);
    while(n--)
    {
        scanf("%d", &a);
        if(a==1)
        {
            printf("0
");
            continue;
        }
        long long ans = Pow(2, a-1);

        printf("%lld
", ans-1);
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/zhengguiping--9876/p/4712517.html