Problem Description
soda has a set S are key set.
 

 

Input
There are multiple test cases. The first line of input contains an integer ), indicating the number of test cases. For each test case:

The first line contains an integer ), the number of integers in the set.
 

 

Output
For each test case, output the number of key sets modulo 1000000007.
 

 

Sample Input
4 1 2 3 4
 

 

Sample Output
0 1 3 7

 

 

给你一个1-n的集合,问你有多少个子集的元素和为偶数

假设偶数有a个,奇数有b个,总数为n:

偶:C(0, a)+ C(1 , a)....... + C(a, a) =   2 ^ a

奇:C(0, b)+ C(2 , b)....... + C(b, b) = 2 ^ (b - 1)

all =  偶 * 奇 - 1(奇偶中都不选的情况);

--->   all  =  2 ^ (a + b - 1)- 1   =   2 ^ (n - 1) -1



#include <iostream>
#include <cstdio>
#include <vector>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long ll;
char ma[1100][1100];
int ln, lm;
const int mod = 1000000007;

ll pow_mod(int a,int n)
{
    if(n == 0)
        return 1;
    ll x = pow_mod(a,n/2);
    ll ans = (ll)x*x%mod;
    if(n %2 == 1)
        ans = ans *a % mod;
    return ans;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);

        ll sum1 = (pow_mod(2,n-1)-1)%mod;
        printf("%I64d\n",sum1);
    }

    return 0;
}


 

  

相关文章:

  • 2022-03-07
  • 2022-01-21
  • 2021-10-15
  • 2022-02-20
  • 2022-12-23
  • 2021-11-17
  • 2021-10-16
  • 2021-11-09
猜你喜欢
  • 2021-05-17
  • 2021-08-10
  • 2021-10-02
  • 2021-09-15
  • 2021-07-06
  • 2021-09-09
  • 2021-12-16
相关资源
相似解决方案