题意:如果一个集合中所有元素加起来是一个偶数,则这个集合是key set.注意输出结果要对1000000007取余!变量还要用longlong或__int64...
这道题实际上就是求2^(n-1)-1的值,由于数据较大,要用到快速幂方法,链接:http://blog.csdn.net/ah_yeah/article/details/52004280
对有一个有n个元素的集合A,其非空子集有2^n-1个。不妨从该集合中任意取出一个奇数,则剩下的(n-1)个元素共有非空子集2^(n-1)-1个。在这些集合各自元素相加的和中:
和为偶数的自然就是key set;而
和为奇数的,加上取出的那个奇数,就成了key set.如此一来集合A的所有元素都用上了,因此它的key set个数就是2^(n-1)-1!!!(其实观察上面的数据就可使推出,上面那些论证也是问度娘的。。)
#include<cstdio>
#define mod 1000000007
long long quickpow(int n){
long long ans=1,base=2;
while(n){
if(n&1)
ans=(base*ans)%mod;
base=(base*base)%mod;
n>>=1;
}
return ans;
}
int main(){
int t;
scanf("%d",&t);
long long n;
while(t--){
scanf("%lld",&n);
printf("%lld\n",quickpow(n-1)-1);
}
return 0;
}