「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 ...
随机推荐
- linux彻底干干净净完全卸载 mysql
本人mysql 装的5.7,liunux版本百度云的centos 6.5 1.查看mysql的安装情况 rpm -qa|grep -i mysql 2.停止mysql服务,删除mysql rpm -e ...
- Beego Learning Notes
Beego框架学习 1.1软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模 ...
- vs code插件大全
一.HTML Snippets 超级使用且初级的H5代码片段以及提示 二.HTML CSS Support 让HTML标签上写class智能提示当前项目所支持的样式 三.Debugger for C ...
- springBoot+MybatisPlus数据库字段使用驼峰命名法时报错
假如有个实体类: package com.jeff.entity; public class User { /** * 主键id */ private Integer id; /** * 登陆名 */ ...
- 微信小程序 列表倒计时
最近要实现一个列表倒计时的功能,写了个demo 展示图 <view class="center colu"> <view class="time&quo ...
- 吴裕雄--天生自然数据结构与算法:java代码实现常用数据结构——链表Linked List
class Node{ // 定义节点类 private String data ; // 保存节点内容 private Node next ; // 表示保存下一个节点 public Node(St ...
- Python学习第十二课——json&pickle&XML模块&OS模块
json模块 import json dic={'name':'hanhan'} i=8 s='hello' l=[11,22] data=json.dumps(dic) #json.dumps() ...
- Linux系统的发展历史和学习前景介绍
2020年了,我想来跟大家聊聊Linux运维这一行业,从几个方面说下行业的现状.如何学好Linux和如何成为专业运维人员以及云服务对于Linux运维的影响. 一.linux行业状况 我们都知道从199 ...
- 31 反射方式给类的属性赋值 和 对象赋值(clone)
1.配置类 package com.da.tool.util.configuration.reflect; /** */ public class JobInfo { private String j ...
- 浏览器输入URL后HTTP请求返回的完整过程
图: