key set

来源:互联网 发布:dnf双开软件 编辑:程序博客网 时间:2024/05/22 02:02
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.
Input
There 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.
Output
For each test case, output the number of key sets modulo 1000000007.
Sample Input
41234
Sample Output
013

7

难点在于找到规律 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;}


0 0
原创粉丝点击