「CF55D」Beautiful numbers
传送门
Luogu
解题思路
毒瘤数位DP,发现一个前缀我们只需要记录它对 \(\operatorname{lcm}(1,2,3,\cdots,9)=2520\) 取模的值即可,所以我们在 DP 时记录一下当前的前缀模2520的值,以及前缀每一位数字的 \(\operatorname{lcm}\) 即可,至于空间的问题,只需要对2520的所有约数离散一下就好了。
细节注意事项
- 咕咕咕
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
typedef long long LL;
int a[20], xxx, mp[2520]; LL dp[20][2520][50];
inline LL dfs(int now, int las, int mod, int lim) {
if (!now) return las % mod == 0;
if (!lim && dp[now][las][mp[mod]] != -1) return dp[now][las][mp[mod]];
LL res = 0; int tp = lim ? a[now] : 9;
for (rg int j = 0; j <= tp; ++j)
res += dfs(now - 1, (las * 10 + j) % 2520, j == 0 ? mod : j * mod / __gcd(j, mod), lim && j == tp);
if (!lim) dp[now][las][mp[mod]] = res;
return res;
}
inline LL solve(LL x) {
int n = 0;
for (rg LL i = x; i; i /= 10) a[++n] = i % 10;
return dfs(n, 0, 1, 1);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
memset(dp, -1, sizeof dp);
for (rg int i = 1; i <= 2520; ++i)
if (2520 % i == 0) mp[i] = ++xxx;
int T; cin >> T;
for (LL l, r; T--; )
cin >> l >> r, cout << solve(r) - solve(l - 1) << endl;
return 0;
}
完结撒花 \(qwq\)
「CF55D」Beautiful numbers的更多相关文章
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
- 【CF55D】Beautiful numbers
[CF55D]Beautiful numbers 题面 洛谷 题解 考虑到如果一个数整除所有数那么可以整除他们的\(lcm\),而如果数\(x\)满足\(x\bmod Lcm(1,2...,9)=r\ ...
- 「CF630C」Lucky Numbers
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description The numbers of all offices in the new ...
- 洛谷 CF55D Beautiful numbers 解题报告
CF55D Beautiful numbers 题意 \(t(\le 10)\)次询问区间\([l,r](1\le l\le r\le 9\times 10^{18})\)中能被每一位上数整除的数的个 ...
- 「LGR-049」洛谷7月月赛 D.Beautiful Pair
「LGR-049」洛谷7月月赛 D.Beautiful Pair 题目大意 : 给出长度为 \(n\) 的序列,求满足 \(i \leq j\) 且 $a_i \times a_j \leq \max ...
- 「CF446C」 DZY Loves Fibonacci Numbers
「CF446C」 DZY Loves Fibonacci Numbers 这里提供一种优美的根号分治做法. 首先,我们考虑一种不太一样的暴力.对于一个区间加斐波那契数的操作 \([a,b]\),以及一 ...
- [暑假集训--数位dp]cf55D Beautiful numbers
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- 「2014-2-26」Unicode vs. UTF-8 etc.
目测是个老问题了.随便一搜,网上各种总结过.这里不辞啰嗦,尽量简洁的备忘一下. 几个链接,有道云笔记链接,都是知乎上几个问题的摘录:阮一峰的日志,1-5 还是值得参考,但是之后的部分则混淆了 Wind ...
随机推荐
- PyQt5窗口操作大全
1.多窗口交互-使用信号与槽函数'''如果一个窗口和一个窗口交互,尽量不要访问窗口B的控件:应该访问与信号绑定的槽函数,从而降低窗口之间的耦合度 例:如果A直接访问B窗口的控件,一旦B窗口的控件发生改 ...
- 多进程 多进程queue
多进程 import multiprocessing import threading import time def thread_run(): print(threading.get_ident( ...
- pwn之exp问题反馈和ASLR认知
如上问题是我执行脚本遇到的,改了脚本几次,依然没变,嗯...... 当我用了百度,据说是ALSR没关,的确,这导致我脚本中的addr是一个随机数,从而攻击失败 ##0x00:引用一下查到的知识:在传统 ...
- lc 0228
目录 ✅ 412. Fizz Buzz 描述 解答 c数字转字符: other's c my c tdo py ✅ 235. 二叉搜索树的最近公共祖先 描述 解答 评价者 思路: c py ✅ 412 ...
- js 子窗口调用父框框方法
父窗口 子窗口
- Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig at ...
- 在visual studio中快速添加代码段
昨天我在网课上,看到老师输入#2之后,立马就出现了一堆代码. 我于是赶紧打开自己的visual studio尝试一下,并没有任何反应. 上网查找,发现visual studio有自定义代码段的功能. ...
- Java 8 stream 实战
概述 平时工作用python的机会比较多,习惯了python函数式编程的简洁和优雅.切换到java后,对于数据处理的『冗长代码』还是有点不习惯的.有幸的是,Java8版本后,引入了Lambda表达式和 ...
- Ngnix调整
1.隐藏版本号,防止针对版本攻击 http { server_tokens off;2.增加并发连接 2.1 worker_processes :改为CPU核数一致,因为异步IO进程是单 ...
- Css——显示2行数据,超出显示...
解决需求——数据较长时,只显示两行,超出显示... .showTwoRow { text-align: left; text-overflow: ellipsis; display: -webkit- ...