Key Set

soda has a set  SS with  nn integers  {1,2,,n}{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  SS are key set.
InputThere are multiple test cases. The first line of input contains an integer  TT  (1T105)(1≤T≤105), indicating the number of test cases. For each test case: 

The first line contains an integer  nn  (1n109)(1≤n≤109), the number of integers in the set. OutputFor each test case, output the number of key sets modulo 1000000007. Sample Input
4
1
2
3
4
Sample Output
0
1
3
7
#include<stdio.h>
const long long n=1e9+7;
long long pow(long long a){
	long long s=2,temp=1;
	while(a){
		if(a&1) temp=temp*s%n;
		s=s*s%n;
		a>>=1;
	}
	return temp;
}
int main(){
	int T;
	long long a;
	scanf("%d",&T);
	while(T--){
		scanf("%lld",&a);
		a-=1;
		printf("%lld\n",pow(a)-1);
	}
	return 0;
} //注意找到规律2^n-1,然后就是位运算的用法。

猜你喜欢

转载自blog.csdn.net/miku531/article/details/79253251
key