12713:[Violet 2]愚蠢的副官

/* Pigonometry */
#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
typedef long long LL;
 
int cnt[5];
LL A, B, lb, ub, ans, dp[20][33][20][14][12], dec[20];
 
int fact[] = {2, 3, 5, 7};
int code[11][4] = {
	{0, 0, 0, 0},
	{0, 0, 0, 0},
	{1, 0, 0, 0},
	{0, 1, 0, 0},
	{2, 0, 0, 0},
	{0, 0, 1, 0},
	{1, 1, 0, 0},
	{0, 0, 0, 1},
	{3, 0, 0, 0},
	{0, 2, 0, 0}
};
 
inline LL ceil(LL a, LL b) {
	return (a + b - 1) / b;
}
 
inline LL floor(LL a, LL b) {
	return a / b;
}
 
inline LL dfs(int x, LL pref) {
	LL b = pref + dec[x] - 1;
	if(pref > ub || b < lb) return 0;
	if(x == 0) return !cnt[0] && !cnt[1] && !cnt[2] && !cnt[3];
 
	bool memo = 0;
	if(pref >= lb && b <= ub) memo = 1;
	if(memo && ~dp[x][cnt[0]][cnt[1]][cnt[2]][cnt[3]]) return dp[x][cnt[0]][cnt[1]][cnt[2]][cnt[3]];
 
	LL res = 0; x--;
	for(int i = (pref != 0); i <= 9; i++) {
		bool flag = 1;
		for(int k = 0; k < 4; k++) flag &= code[i][k] <= cnt[k];
		if(!flag) continue;
 
		for(int k = 0; k < 4; k++) cnt[k] -= code[i][k];
		res += dfs(x, pref + dec[x] * i);
		for(int k = 0; k < 4; k++) cnt[k] += code[i][k];
	}
 
	if(memo) dp[x + 1][cnt[0]][cnt[1]][cnt[2]][cnt[3]] = res;
	return res;
}
 
inline void solve(int x, LL prod) {
	if(prod > 1000000000 || prod * prod > B) return;
	if(x == 4) {
		lb = ceil(A, prod); ub = floor(B, prod);
		ans += dfs(18, 0);
		return;
	}
 
	solve(x + 1, prod);
	cnt[x]++;
	solve(x, prod * fact[x]);
	cnt[x]--;
}
 
int main() {
	dec[0] = 1;
	for(int i = 1; i < 19; i++) dec[i] = (dec[i - 1] << 3) + (dec[i - 1] << 1);
	memset(dp, -1, sizeof(dp));
 
	scanf("%lld%lld", &A, &B);
 
	solve(0, 1);
 
	printf("%lld\n", ans);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值