soda has a set $S$ with $n$ integers $\{1, 2, \dots, 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.
There are multiple test cases. The first line of input contains an integer $T$ $(1 \le T \le 10^5)$, indicating the number of test cases. For each test case: The first line contains an integer $n$ $(1 \le n \le 10^9)$, the number of integers in the set.
For each test case, output the number of key sets modulo 1000000007.
4
1
2
3
4
0
1
3
7
求1 2 3 ... n 的 所有子集中和为偶数的子集个数,mod 1000000007
数学归纳法证明和为偶数的子集有2n-1-1个:
综合1,2得系列1 2 ... n 和为偶数的子集有2n-1-1个
接下来用快速幂即可。
#include<stdio.h>
#define ll long long
const ll M=1e9+7;
ll t,n;
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
ll k=2,ans=1;
n--;
while(n){
if(n&1)ans=(ans*k)%M;
k=(k*k)%M;
n>>=1;
}
printf("%lld\n",ans-1);
}
}