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-n的集合,问你有多少个子集的元素和为偶数

假设偶数有a个,奇数有b个,总数为n:

偶:C(0, a)+ C(1 , a)....... + C(a, a) =   2 ^ a

奇:C(0, b)+ C(2 , b)....... + C(b, b) = 2 ^ (b - 1)

all =  偶 * 奇 - 1(奇偶中都不选的情况);

--->   all  =  2 ^ (a + b - 1)- 1   =   2 ^ (n - 1) -1

#include <iostream>
#include <cstdio>
#include <vector>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long ll;
char ma[1100][1100];
int ln, lm;
const int mod = 1000000007; ll pow_mod(int a,int n)
{
if(n == 0)
return 1;
ll x = pow_mod(a,n/2);
ll ans = (ll)x*x%mod;
if(n %2 == 1)
ans = ans *a % mod;
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n); ll sum1 = (pow_mod(2,n-1)-1)%mod;
printf("%I64d\n",sum1);
} return 0;
}

  

2015 多校联赛 ——HDU5363(快速幂)的更多相关文章

  1. 2015 多校联赛 ——HDU5302(矩阵快速幂)

    The Goddess Of The Moon Sample Input 2 10 50 12 1213 1212 1313231 12312413 12312 4123 1231 3 131 5 5 ...

  2. HDU_4965 Fast Matrix Calculation 2014多校9 矩阵快速幂+机智的矩阵结合律

    一开始看这个题目以为是个裸的矩阵快速幂的题目, 后来发现会超时,超就超在  M = C^(N*N). 这个操作,而C本身是个N*N的矩阵,N最大为1000. 但是这里有个巧妙的地方就是 C的来源其实 ...

  3. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  7. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  8. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

随机推荐

  1. 项目Alpha冲刺Day8

    一.会议照片 二.项目进展 1.今日安排 前端界面框架基本完成,剩下侧边栏与权限相关部分未完成.前端路由异常拦截完成.项目结构与开发流程规定完成.后台开发规定小变更. 2.问题困难 组件的拆分与否和组 ...

  2. (转)如何在Eclipse中查看JDK类库的源代码

    在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 “window”-> "Preferences" -> "Java" -> & ...

  3. 团队作业4——第一次项目冲刺(Alpha版本)

    第一天http://www.cnblogs.com/ThinkAlone/p/7861070.html 第二天http://www.cnblogs.com/ThinkAlone/p/7861191.h ...

  4. JAVAGUI设计步骤

    ①创建容器 首先要创建一个GUI应用程序,需要创建一个用于容纳所有其它GUI组件元素的载体,Java中称为容器.典型的包括窗口(Window).框架(Frame/JFrame).对话框(Dialog/ ...

  5. const volatile同时限定一个类型int a = 10

    const和volatile放在一起的意义在于: (1)本程序段中不能对a作修改,任何修改都是非法的,或者至少是粗心,编译器应该报错,防止这种粗心: (2)另一个程序段则完全有可能修改,因此编译器最好 ...

  6. Network in Network

     论文要点: 用更有效的非线性函数逼近器(MLP,multilayer perceptron)代替 GLM 以增强局部模型的抽象能力.抽象能力指的模型中特征是对于同一概念的变体的不变形. 使用 gl ...

  7. DBA 小记 — 分库分表、主从、读写分离

    前言 我在上篇博客 "Spring Boot 的实践与思考" 中比对不同规范的 ORM 框架应用场景的时候提到过主从与读写分离,本篇随笔将针对此和分库分表进行更深入地探讨. 1. ...

  8. emqtt 试用(五)emq 的用户密码认证

    MQTT 认证设置 EMQ 消息服务器认证由一系列认证插件(Plugin)提供,系统支持按用户名密码.ClientID 或匿名认证. 系统默认开启匿名认证(anonymous),通过加载认证插件可开启 ...

  9. 新概念英语(1-15)Your passports please

    Is there a problem wtih the Customers officer? A:Are you Swedish? B:No. We are not. We are Danish. A ...

  10. 新概念英语(1-37)Making a bookcase

    What is Susan's favourite color ? A:You're working hard, Georage. What are you doing? B:I am making ...