HDU 5363 Key Set(快速幂取模)

Key Set


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 of S are key set.
 

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

The first line contains an integer n (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
4
1
2
3
4
 

Sample Output
0
1
3
7
 

 

 1 #include<cstdio>
 2 using namespace std;
 3 
 4 const long long int mod=1000000007;
 5 
 6 void quickmod(int a,int b,long long n)
 7 {
 8     long long res=1,temp=a%n;
 9     while(b)
10     {
11         if(b&1)res=(res*temp)%n;
12         temp=(temp*temp)%n;
13         b>>=1;
14     }
15     printf("%lld
",res-1);
16 }
17 
18 int main()
19 {
20     int t,n;
21     scanf("%d",&t);
22     while(t--)
23     {
24         scanf("%d",&n);
25         quickmod(2,n-1,mod);
26     }
27     return 0;
28 }
原文地址:https://www.cnblogs.com/homura/p/4711429.html