【 HDU - 5363】Key Set(水题,快速幂,组合数学)

题干:

soda has a set SS with nn integers {1,2,…,n}{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 SS are key set.

Input

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

The first line contains an integer nn (1≤n≤109)(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

解题报告:

   这应该算是多校里面的大水题了吧?(ps:当时写的快速幂也太丑陋了吧、、、)

因为集合S中的元素是从1开始的连续的自然数,所以所有元素中奇数个数与偶数个数相同,或比偶数多一个。另外我们要知道偶数+偶数=偶数,奇数+奇数=偶数,假设现在有a个偶数,b个奇数,则

根据二项式展开公式

以及二项式展开式中奇数项系数之和等于偶数项系数之和的定理

可以得到

最后的结果还需减去

即空集的情况,因为题目要求非空子集

所以最终结果为

部分题解来自这里

AC代码:

#include<bits/stdc++.h>
#define mod 1000000007
typedef long long ll;using namespace std;
ll n;
ll qpow(ll a,ll k) {ll ans = 1;while(k > 0) {if(k&1) {ans*=a;}ans%=mod;a*=a;a%=mod;k>>=1;}return ans%mod;
}
int main() {int t;ll ans;cin>>t;while(t--) {scanf("%lld", &n);ans = qpow(2,n%mod-1);printf("%lld\n",ans-1);}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441221.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ajax 更新模型数据_DuangDuangDuang,重点来啦!高薪全靠它——百战Web前端课程更新03.11...

百战程序员九大专业运营&#xff0c;周周有课程更新&#xff0c;保持行业领先。本次更新课程Web前端第三十阶段经典面试题解析章节1—5及课程资料。本次更新可谓是诚意满满&#xff0c;针对市场面试需要&#xff0c;总结经典面试题集&#xff0c;为你揭开企业技术要求的神秘面纱…

河南省高考让不让带计算机,河南高考2018严禁携带的东西有哪些?这种衣服不能进考场...

近日&#xff0c;河南省开启高考“严控”模式&#xff0c;将依法从严治考&#xff0c;关怀服务考生&#xff0c;对任何破坏高考安全工作的行为“零容忍”。带金属的鞋带、鞋眼、鞋底&#xff0c;带金属挂钩和钢圈的内衣、腰带、裤子挂钩、衣扣通通不能进考场&#xff01;  快…

【POJ - 2262】Goldbach's Conjecture (数论,哥德巴赫猜想,知识点结论)

题干&#xff1a; In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of two odd prime numbers.For example: 8 …

msg计算机指令怎样用,WIN7里使用msg命令发送消息失败

使用服务&#xff1a;WIN7里使用msg命令发送消息一、msg语法MSG {username | sessionname | sessionid | filename | *}[/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]username 标识指定的用户名。sessionname 会话名。sessionid 会话…

combox 增加请选择_娱乐测试:选择四种花束中的一种,测试你对婚姻的看法

阅读本文前&#xff0c;请您先点击上面的“落落天使”&#xff0c;再点击“关注”&#xff0c;这样您就可以继续免费收到文章了。每天都有分享&#xff0c;完全是免费订阅&#xff0c;请放心关注。 …

【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)

题干&#xff1a; For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n p1 p2 This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. …

计算机突然断电恢复供电后,电脑突然断电的坏处有哪些?

对于经常使用计算机进行办公的用户而言&#xff0c;最可怕的事情是计算机在保存文件之前突然断电关机。但是&#xff0c;这对于计算机本身根本不是问题&#xff0c;只要计算机能够正常运行。但是&#xff0c;如果断电导致以下任何一种情况&#xff0c;则需要小心&#xff01;1、…

python函数实例解析_python支持返回函数的实例解析

这篇文章主要介绍了python支持返回函数的实例解析,小编觉得挺不错的&#xff0c;现在分享给大家&#xff0c;也给大家做个参考。一起跟随小编过来看看吧最近接触python,看到了python中返回函数的概念&#xff0c;以前只接触过函数返回值&#xff0c;比如python就可以返回int,st…

【CodeForces - 260D】Black and White Tree (思维构造,猜结论,细节,构造一棵树)

题干&#xff1a; The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesnt contain any cycles. Each node of the graph is painted black or white in such a mann…

手游 自建服务器,英灵神殿自己搭建服务器怎么弄

英灵神殿是一款冒险生存类游戏&#xff0c;在英灵神殿游戏中小伙伴要自己搭建服务器才能玩&#xff0c;那么要怎么搭建&#xff0c;有什么技巧吗?接下来和小编一起来看看吧!Valheim英灵神殿服务器搭建技巧第一步&#xff1a;SteamCMD和安装内容从这里下载SteamCMD。将其提取到…

描写火车站场景_关于描写火车站的句子

关于描写火车站的句子关于描写火车站的句子所以至今&#xff0c;我仍很爱乘火车&#xff0c;卧铺&#xff0c;靠在枕头上看书&#xff0c;沉沉睡去&#xff0c;听铁轨一层一层的荡漾&#xff0c;在记忆中昏暗地穿行&#xff0c;如果我爱谁&#xff0c;我们一定会乘火车去很远的…

【POJ - 1463】Strategic game (树上最小点覆盖,树形dp)

题干&#xff1a; Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree…

vue css自定义标签,Vue如何使用CSS自定义变量

目录在 css 自定义变量的功能以及出来许久了&#xff0c;但实际开发中大家使用并不多。归其原因是因为 less、sass 等预处理器已经拥有定义变量的功能&#xff0c;以及Vue、react很方便设置 style 样式&#xff0c;大家可能觉得使用 css 定义变量不方便且没必要。实则不然举个最…

【CodeForces - 260A】Adding Digits (思维构造)

题干&#xff1a; Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times. One operation of lengthening a number means adding exactly one digit to the number (in the…

人工智能在fpga的具体应用_人工智能带动了FPGA的发展

未来几年&#xff0c;人工智能芯片的需求将急剧上升。联合市场研究公司(Allied Market Research)预估&#xff0c;未来5年&#xff0c;人工智能芯片的需求将以每年近50&#xff05;的速度增长&#xff0c;因为该技术将在汽车、医疗保健等多个领域得到广泛应用。Xilinx深知其中存…

恐怖黎明稳定服务器,恐怖黎明新人联机图文教程 怎么联机-游侠网

恐怖黎明怎么联机?不少玩家想体验联机&#xff0c;但是不知道方法&#xff0c;小编这里给大家带来了新人联机图文教程&#xff0c;不会的萌新来学习下吧。联机图文教程:A1 联机&#xff1a;因为gd(grimdawn)没有自己的战网平台(就是专供联机玩的专职服务器 server)&#xff0c…

【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)

题干&#xff1a; A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". Well say that some date is mentioned in the Prophesy if there is a su…

github 上传代码_leetcode爬虫:爬取代码;生成readme;上传github

Leetcode-Helper哪个程序员 不想一键下写过的代码&#xff0c;自动上传Github&#xff0c;并且还能生成好看的README呢&#xff1f;有用的话点个⭐吧&#xff0c;谢谢你。Leetcode-Helper传送门​github.com主要功能 模拟登陆力扣中国站(leetcode-cn)爬取每题提交的ac代码&…

绝地求生信号枪只能在服务器吗,绝地求生信号枪怎么用?信号枪刷新点及用法详解...

绝地求生信号枪怎么用&#xff1f;信号枪刷新点及用法详解2018-03-15 15:22:12来源&#xff1a;吃鸡小助手编辑&#xff1a;野狐禅评论(0)绝地求生近日更新中悄悄加入了信号枪&#xff0c;引得广大玩家热情满满的在游戏中寻找&#xff0c;信号枪到底怎么用呢&#xff1f;下面就…

spring的beanutils工具类_基于spring-beans实现工具类BeanUtils基于Class实例化注入对象及查找方法、复制属性等操作...

一、前言基于spring-beans(4.1.4)的工具类org.springframework.beans.BeanUtils对注入spring对象按照Class实例化instantiateClass、class对象方法名称methodName查找findMethod、属性查找对于class类信息findPropertyType、对象属性复制copyProperties等常用操作&#xff0c;具…