HDU 5363-K - Key Set-递推
来源:互联网 发布:4g网络1g流量能用多久 编辑:程序博客网 时间:2024/05/18 02:51
可以发现 对于奇数,1 2 3 . ...n 子集有2^n 个,因为n为奇数,所以求和为(n+1)*n/2必为偶数,只有【1】这个集合不是偶数 所以 结果为2^n-1
偶数则为【 2^(n-1)-1 】的2倍+1
因为假设奇数k的个数为x 则 下一位 为k+1 ,k+1的前k个数组成满足条件的子集有x个,每个子集加一个元素k+1(为偶数,不影响),又得到x个子集,最后还有一个子集为 k+1本身
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <queue>#include <map>#include <set>#include <vector>using namespace std;#define mod 1000000007__int64 powe_m(__int64 a,__int64 b,__int64 c){__int64 ans=1; __int64 tmp=a;while(b!=0){ if (b&1) ans=ans*tmp%c; //不可以写 ans=ans*ans%c 结果会变tmp=tmp*tmp%c;b=b>>1;} return ans%c; }int main(){__int64 t,n;scanf("%I64d",&t);while(t--){__int64 ans;scanf("%I64d",&n);if (n%2==1){ans=powe_m(2,n-1,1000000007)-1; }else{__int64 tmp=n-1;ans=powe_m(2,tmp-1,mod)-1;ans=(2*ans+1)%mod;}printf("%I64d\n",ans);}return 0;}
0 0
- HDU 5363-K - Key Set-递推
- HDU-5363 Key Set 【快速幂取模+递推】
- HDU 5363 Key Set
- HDU 5363 Key Set
- hdu 5363 Key Set
- HDU 5363 Key Set
- HDU 5363 Key Set
- HDU 5363 Key Set
- HDU - 5363 Key Set
- hdu 5363 Key Set
- hdu 5363 Key Set (2015多校第六场第11题)找规律推公式
- hdu 5363 Key Set 矩阵快速幂
- HDU 5363 Key Set(快速幂)
- hdu 5363 Key Set (快速幂取模)
- HDU 5363 Key Set(快速幂取余)
- Hdu 5363 Key Set【快速幂运算】
- hdu 5363 Key Set(水)
- hdu 5363 Key Set 简单题
- 位运算
- Asp.Net的简介
- Hibernate 基本配置和应用
- Linux socket编程的心跳机制总结
- Battle City
- HDU 5363-K - Key Set-递推
- 总结一下 matplotlib 画图常用功能
- UI0_带分区的省市区
- Java心得13
- CodeForces-556C Case of Matryoshkas
- Visual Studio远程调试的使用
- 生成素数序列----埃拉托斯特尼筛法
- 关于pymongo两种连接方法MongoClient和Connection连接mongodb的写入效率分析
- 安装Win7ghost 之后,发现鼠标和键盘没有反应,失效