hdu 5363 Key Set【快速幂求余】

来源:互联网 发布:java多线程运行机制 编辑:程序博客网 时间:2024/05/21 12:41

Key Set

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1314    Accepted Submission(s): 734


Problem Description
soda has a set S with n integers {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 ofS are key set.
 


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

The first line contains an integer n(1n109), 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
0137

求出2^n-1,然后再-1得出结果。也算是给以后的自己留一份模板

#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define mod 1000000007int main(){    int t;    cin>>t;    while(t--)    {        int n;        cin>>n;        n--;        long long int  tmp=2;        long long int  ans=1;        while(n)        {            if(n%2==1)            {                ans=(ans*tmp)%mod;                n-=1;            }            else            {                tmp=(tmp*tmp)%mod;                n/=2;            }        }        cout<<ans-1<<endl;    }}













0 0