Key Set

http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=594

Key Set

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


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 (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
4 1 2 3 4
 
Sample Output
0 1 3 7
 
直接输出2的n-1次方-1?当然2的10的9次方的次方肯定很大,然而结果只是对其求余与1000000007,所以快速幂,对每次都求余,就不会超出类型啦
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 typedef long long LL;
 7 const LL mod = 1000000007;
 8 LL Pow (LL x, LL y)
 9 {
10     LL ans = 1;
11     while (y)
12     {
13         if (y % 2)
14             ans = ans * x % mod;
15         x = x * x % mod;
16         y /= 2;
17     }
18     return ans;
19 }
20 int main ()
21 {
22     LL t, n;
23     scanf ("%lld", &t);
24     while (t --)
25     {
26         scanf ("%lld", &n);
27         LL ans = Pow (2, n-1);
28         printf ("%lld
", ans-1);
29     }
30     return 0;
31 }
让未来到来 让过去过去
原文地址:https://www.cnblogs.com/Tinamei/p/4707871.html