「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.打印机操作(打印默认文本里面的内容)from PyQt5 import QtGui,QtWidgets,QtPrintSupportfrom PyQt5.QtWidgets import *imp ...
- 整合SSM
SSM整合:Spring - SpringMVC - MyBatis 1.Spring - MyBatis : 需要整合:将MyBatis的SqlSessionFactory 交给Spr ...
- JSONObject、 JsonObject、阿里fastJson、谷歌gson区别
JSON:JavaScript Object Notation Java对象表示法 Java中并没有内置的 JSON 解析,需要使用第三方类库.常用的类库如下 一.Gson : 古河开发的JSON 库 ...
- vue 和 jquery混合使用
有时候只要想到要用的 vue.js 的时候就会惯性的想起用vue-cli手脚架搭建一个项目,但是有时候的业务场景并不适合用vue-cli手脚架,这个时候使用vue+jquery混合使用,把他们的优点结 ...
- 一个IP与多个域名绑定
方法一:通过端口区分 方法二:通过serverName区分(推荐) 1.httpd.conf打开 virtual host虚拟主机配置 2.httpd-vhost.conf 添加配置 <Virt ...
- ES 创建mapping
mapping的写入与查看首先创建一个索引: curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"{&q ...
- Solidity基本数据结构
任何一个智能合约都会在最开头表示使用的编译器版本 如:prama solidity ^0.4.0 数组: //静态数组 大小长度确定 uint[2] fixedArray; //动态数组,可以随意添加 ...
- RestTemplate HttpMessageConverter报错的解决方案no suitable HttpMessageConverter
错误 no suitable HttpMessageConverter found for response type and content type [text/html;charset=UTF- ...
- 学习 Python,怎能不懂点PEP 呢?
或许你是一个初入门 Python 的小白,完全不知道 PEP 是什么.又或许你是个学会了 Python 的熟手,见过几个 PEP,却不知道这玩意背后是什么.那正好,本文将系统性地介绍一下 PEP,与大 ...
- Aery的UE4 C++游戏开发之旅(4)加载资源&创建对象
目录 资源的硬引用 硬指针 FObjectFinder<T> / FClassFinder<T> 资源的软引用 FSoftObjectPaths.FStringAssetRef ...