soda has a set
S
S with
n
n 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
S
S are key set.
The first line contains an integer n n (1≤n≤109) (1≤n≤109), the number of integers in the set.
4 1 2 3 4
0 1 37
难点在于找到规律 2^n-1
#include<cstdio> const long long N=1e9+7; long long power(long long a){ long long b=2; long long temp = 1; while (a){ if (a&1){ temp=temp*b%N; } b = b*b%N; a>>=1; } return temp; } int main(){ int t; scanf("%d",&t); while (t--){ long long n; scanf("%lld",&n); n-=1; printf("%lld\n",power(n)-1); } return 0; }