BZOJ3209 花神的数论题

[Solution]

Digit DP. Count numbers whose digit sum in binary equal to k.

The hole in this problem is that 10000007(10^7+7) isn't a prime.


[Code]

#include <cstdio>
#include <memory.h>
#include <algorithm>

using namespace std;

typedef long long qw;

#ifdef WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int maxn = 80;
const qw mod = 10000007;

qw f[maxn][maxn][2], a, s, n;

#define pow2(x) (1LL<<(x))
#define incm(a,b) (((a)+=(b))%=mod)
#define inc(a,b) ((a)+=(b))

qw getBit(qw x) {
	qw s = 0;
	while (x >>= 1)
		s ++;
	return s;
}

qw modPow(qw a, qw x) {
	qw s = 1;
	for (; x; x >>= 1, a = a * a % mod)
		if (x & 1)
			s = s * a % mod;
	return s;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif

	memset(f, 0, sizeof(f));
	scanf(lld, &a);
	n = getBit(a);
	f[0][0][0] = 1;
	f[0][1][0] = 1;
	f[0][0][1] = 1;
	f[0][a & 1][1] = 1;
	for (int i = 1; i <= n; i ++)
		for (int j = 0; j <= n + 1; j ++) {
			inc(f[i][j][0], f[i - 1][j][0]);
			if (j)
				inc(f[i][j][0], f[i - 1][j - 1][0]);
			if ((a >> i) & 1) {
				if (j)
					inc(f[i][j][1], f[i - 1][j - 1][1]);
				inc(f[i][j][1], f[i - 1][j][0]);
			}
			else
				inc(f[i][j][1], f[i - 1][j][1]);
		}
	s = 1;
	for (int i = 1; i <= n + 1; i ++)
		s = modPow(i, f[n][i][1]) * s % mod;
	printf(lld "\n", s);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值