題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5363
題意:給你一個有1到n的n個數的集合,求這個集合的非空子集的子集所有元素的和爲偶數的子集個數
思路:因爲和爲偶數,所以一定是由2*x個奇數+y個偶數組成,從中就可以推出公式爲2^(n-1)-1
代碼:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL __int64
#define mod 1000000007
LL quick_pow(LL n)
{
LL ans=1;
LL a=2;
while(n)
{
if(n&1)
ans=ans*a%mod;
a=a*a%mod;
n>>=1;
}
return ans;
}
int main()
{
int T,n;
while(scanf("%d",&T)==1)
{
while(T--)
{
scanf("%d",&n);
printf("%I64d\n",quick_pow(n-1)-1);
}
}
return 0;
}