HDU Problem - 5363 Key Set 【快速幂】
2016-07-23 14:45
260 查看
Key Set
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1763 Accepted Submission(s): 928
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output the number of key sets modulo 1000000007.
[align=left]Sample Input[/align]
4
1
2
3
4
[align=left]Sample Output[/align]
0
1
3
7
对于一个有n的元素的集合,组成的非空子集有2^n - 1个,其中和为奇数的个数比和为偶数的个数多一个。注意利用快速幂函数,不要超过了long long。
#include <stdio.h> __int64 pow(__int64 x, __int64 y) { __int64 res = 1; __int64 base = x; y -= 1; while (y) { if (y&1) res = base*res%1000000007; base = base*base%1000000007; y >>= 1; } return res; } int main() { int t; __int64 n; scanf("%d", &t); while (t--) { scanf("%I64d", &n); printf("%I64d\n", pow(2, n) - 1); } return 0; }
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- 计算字符串最后一个单词长度
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002