[BZOJ3209]花神的数论题 组合数+快速幂
2024-09-29 15:56:34
3209: 花神的数论题
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 2498 Solved: 1129
[Submit][Status][Discuss]
Description
背景
众所周知,花神多年来凭借无边的神力狂虐各大 OJ、OI、CF、TC …… 当然也包括 CH 啦。
描述
话说花神这天又来讲课了。课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了。
花神的题目是这样的
设 sum(i) 表示 i 的二进制表示中 1 的个数。给出一个正整数 N ,花神要问你
派(Sum(i)),也就是 sum(1)—sum(N) 的乘积。
Input
一个正整数 N。
Output
一个数,答案模 10000007 的值。
Sample Input
样例输入一
3
Sample Output
样例输出一
2
HINT
对于样例一,1*1*2=2;
数据范围与约定
对于 100% 的数据,N≤10^15
Source
枚举1的个数,组合数+快速幂即可。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define mod 10000007
#define LL long long
using namespace std;
LL c[][];
void pre() {
for(int i=;i<=;i++) c[i][]=;
for(int i=;i<=;i++) for(int j=;j<=i;j++) c[i][j]=c[i-][j]+c[i-][j-];
}
LL w[];
LL n,len;
LL power(LL a,LL b) {
LL ans=;
while(b) {
if(b&) ans*=a,ans%=mod;
a*=a;a%=mod;
b>>=;
}
return ans;
}
LL cnt(LL x) {
LL ans=;
for(int i=len;i>=;i--) {
if(w[i]) ans+=c[i-][x],x--;
if(x<) break;
}
return ans;
}
int main() {
pre();
scanf("%lld",&n);
n++;
while(n) {
w[++len]=n&;
n>>=;
}
LL ans=1LL;
for(int i=;i<=len;i++) ans*=power(i,cnt(i)),ans%=mod;
printf("%lld",ans);
}
最新文章
- .NET深入实战系列—Linq to Sql进阶
- espcms特殊标签
- C++ 利用 libxl 将 Excel 文件转化为 Xml 文件
- jquery-1.3.2.js
- SharePoint Foundation 2013 with SP1
- Match:Blue Jeans(POJ 3080)
- JSTL 的 if else : 有 c:if 没有 else 的处理
- 转载:奇异值分解(SVD) --- 线性变换几何意义(下)
- google proto buffer安装和简单示例
- TSQL基础(二)
- RHCA442学习笔记-Unit10内存地址及分配
- ARM开发板系统移植-----kernel的编译
- 高健壮性css---Float详细
- [实验]通过内核Patch去掉iOS-v4.3.3的沙盒特性
- 覆盖问题<;shui>;
- Servlet 详解
- ppt制作元素采集
- python学习(十一)
- linux系统常用的基本命令分类
- tcp_协议基础