3209: 花神的数论题

题意:求\(1到n\le 10^{15}\)二进制1的个数的乘积,取模1e7+7


二进制最多50位,我们统计每种1的个数的数的个数,快速幂再乘起来就行了

裸数位DP..\(f[i][j]\)i位数j个1的方案数..不考虑天际线就是组合数...




比较坑的地方是本题求f要取模\(phi(1e7+7)\),然后它并不是质数...

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=60;
const ll P=10000007, Phi=9988440;
inline ll read(){
char c=getchar();ll x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
} ll n, ans=1; int a[N], len;
ll Pow(ll a, ll b) { //printf("Pow %lld %lld\n",a,b);
ll ans=1;
for(; b; b>>=1, a=a*a%P)
if(b&1) ans=ans*a%P;
return ans;
}
ll f[N][N];
ll dfs(int d, int sky, int x) {
if(d==0) return x==0;
if(!sky) return f[d][x];
int lim = sky ? a[d] : 1;
ll now=0;
for(int i=0; i<=lim; i++) (now += dfs(d-1, sky && i==lim, x-i))%=Phi;
return sky ? now : f[d][x]=now;
}
int main() {
freopen("in","r",stdin);
n=read();
while(n) a[++len]=n&1, n>>=1;
//memset(f,-1,sizeof(f));
f[0][0]=1;
for(int i=1; i<=len; i++){
f[i][0]=1;
for(int j=1; j<=i; j++) f[i][j]=(f[i-1][j]+f[i-1][j-1])%Phi;
}
for(int i=2; i<=len; i++)
ans = ans*Pow(i, dfs(len, 1, i) )%P;
printf("%lld", ans);
}

BZOJ 3209: 花神的数论题 [数位DP]的更多相关文章

  1. bzoj 3209 花神的数论题 —— 数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 算是挺简单的数位DP吧,但还是花了好久才弄明白... 又参考了博客:https://b ...

  2. BZOJ 3209 花神的数论题 数位DP+数论

    题目大意:令Sum(i)为i在二进制下1的个数 求∏(1<=i<=n)Sum(i) 一道非常easy的数位DP 首先我们打表打出组合数 然后利用数位DP统计出二进制下1的个数为x的数的数量 ...

  3. BZOJ3209: 花神的数论题(数位DP)

    题目: 3209: 花神的数论题 解析: 二进制的数位DP 因为\([1,n]\)中每一个数对应的二进制数是唯一的,我们枚举\(1\)的个数\(k\),计算有多少个数的二进制中有\(k\)个\(1\) ...

  4. 【BZOJ3209】花神的数论题 数位DP

    [BZOJ3209]花神的数论题 Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级 ...

  5. bzoj 3209 花神的数论题——二进制下的数位dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 可以枚举 “1的个数是...的数有多少个” ,然后就是用组合数算在多少位里选几个1. ...

  6. BZOJ 3209: 花神的数论题【数位dp】

    Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了. ...

  7. [数位dp] bzoj 3209 花神的数论题

    题意:中文题. 思路:和普通数位dp一样,这里转换成二进制,然后记录有几个一. 统计的时候乘起来就好了. 代码: #include"cstdlib" #include"c ...

  8. [BZOJ 3209] 花神的数论题 【数位统计】

    题目链接: BZOJ - 3209 题目大意 设 f(x) 为 x 的二进制表示中 1 的个数.给定 n ,求 ∏ f(i)     (1 <= i <= n) . 题目分析 总体思路是枚 ...

  9. bzoj3209 花神的数论题——数位dp

    题目大意: 花神的题目是这样的 设 sum(i) 表示 i 的二进制表示中 1 的个数.给出一个正整数 N ,花神要问你 派(Sum(i)),也就是 sum(1)—sum(N) 的乘积. 要对1000 ...

随机推荐

  1. int ,long long等范围

    unsigned   int   0-4294967295   int   -2147483648-2147483647 unsigned long 0-4294967295long   -21474 ...

  2. IOS开发之纯代码界面--基本控件使用篇 ┊

    http://www.cocoachina.com/bbs/read.php?tid=131516

  3. 【开发技术】web.xml vs struts.xml

    web.xml用来配置servlet,监听器(Listener),过滤器(filter),还有404错误跳转页面,500,等还配置欢迎页面等,总之一句话,就是系统总配置方案写在web.xml中 str ...

  4. Linuxc - gdb调试程序

    指针实现变量交换值 #include <stdio.h> void change(int *a,int *b) { int tmp = *a; *a = *b;// 将指针a所在地址的值, ...

  5. Linux - ubuntu 设置固定ip和设置dns

    ubuntu 设置固定ip和设置dns 1.ifconfig 查看网卡名称 root@jiqing-virtual-machine:~# ifconfig ens32 Link encap:以太网 硬 ...

  6. web-based installer and executable installer in python 3 ,what is the difference between them?

    Welcome to Python! This applies to all programs, not just python: An executable installer has every ...

  7. iptables nat及端口映射

    iptables nat及端口映射 发布: 2010-6-11 15:05 | 作者: admin | 来源: SF NetWork 门户网站 iptables 应用初探(nat+三层访问控制) ip ...

  8. u8g2库的相关资料

    2017-12-1309:13:32更新51论坛上的帖子,大神自己写的库文件,待调试! http://www.51hei.com/bbs/forum.php?mod=viewthread&ti ...

  9. Java 调用python说明文档

    Java 调用python说明文档 通过java调用python脚本主要如下三种方式: 1.直接执行python脚本: 2.执行python.py文件: 3.使用Runtime.getRuntime( ...

  10. MTU,MSS基本概念

    传输层: 对于UDP协议来说,整个包的最大长度为65535,其中包头长度是65535-20=65515: 对于TCP协议来说,整个包的最大长度是由最大传输大小(MSS,Maxitum Segment ...