求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); } }
原文:http://www.cnblogs.com/flipped/p/5183794.html