C - Key Set

图片标题
求集合中和为偶数的非空子集的个数 2^(n-1)-1

#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <map>
#include <string>
#include <set>
#include <stack>
#include<queue>
using namespace std;
#define forseach(i,j,n) for(int i=j;i<n;i++)
#define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//#define PI acos(-1)
typedef long long ll;
const int maxn = 1e5;

ll mypow(ll x,ll y,ll &mod)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans=(x*ans)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return ans;
}
int main()
{
	//debug;
	ios;
	int T;
	ll mod=1000000007;
	cin>>T;
	while(T--)
	{
		ll x=2,n;
		cin>>n;
		n--;
		cout<<mypow(x,n,mod)-1<<'\n';
	}
    return 0;
}


全部评论

相关推荐

头像
04-09 14:29
Java
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务