HDU 5363 Key Set

Problem Description
soda has a set  S  with  n  integers  {1,2,,n} . A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of  S  are key set.
 

Input
There are multiple test cases. The first line of input contains an integer  T   (1T105) , indicating the number of test cases. For each test case:

The first line contains an integer  n   (1n109) , the number of integers in the set.
 

Output
For each test case, output the number of key sets modulo 1000000007.
 

Sample Input
   
   
   
   
4 1 2 3 4
 

Sample Output
   
   
   
   
0 1 3 7

找到规律就ok了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<functional>
using namespace std;
typedef long long ll;
const ll base = 1000000007;
ll n, T;

ll get(ll x, ll y)
{
	ll ans = 1;
	for (; y; y >>= 1)
	{
		if (y & 1) (ans *= x) %= base;
		(x *= x) %= base;
	}
	return (ans + base - 1) % base;
}

int main()
{
	scanf("%lld", &T);
	while (T--)
	{
		scanf("%lld", &n);
		printf("%lld\n", get(2, n - 1));
	}
	return 0;
}


你可能感兴趣的:(HDU)