CF 55 D. Beautiful numbers
D. Beautiful numbers
题意:
求[L,R]中多少个数字可以整除它们的每一位上的数字。
分析:
要求模一些数字等于0等价于模它们的lcm等于0,所以可以记录当前出现的数字的lcm,最后判断组成的数字是否模lcm等于0。
但是这个数字太大记录不下。根据一个性质a%b=(a%kb)%b,所以可以记录当前的数字模2520的值,最后模一下lcm。
这样的状态是$20 \times 2520 \times 2520$的,状态太大了,考虑如何缩小空间。因为1~9的lcm只能是50个左右,所以可以将第三维压成50。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline LL read() {
LL x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
LL dp[][][N + ];
int num[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
int a[], pos[N + ]; int gcd(int a,int b) { return b == ? a : gcd(b, a % b); }
int getlcm(int a,int b) { return a * b / gcd(a, b); } LL dfs(int p,int lcm,int now,bool lim) {
if (p == ) return lcm && now % num[lcm] == ;
if (!lim && ~dp[p][lcm][now]) return dp[p][lcm][now];
int u = lim ? a[p] : ;
LL ans = ;
for (int i = ; i <= u; ++i) {
int t = lcm ? pos[getlcm(num[lcm], max(i, ))] : i;
ans += dfs(p - , t, (now * + i) % N, lim && i == u);
}
if (!lim) dp[p][lcm][now] = ans;
return ans;
}
LL solve(LL x) {
if (x <= ) return ;
int pos = ;
while (x) {
a[++pos] = x % ; x /= ;
}
return dfs(pos, , , );
}
int main() {
memset(dp, -, sizeof(dp));
for (int i = ; i < ; ++i) pos[num[i]] = i;
for (int T = read(); T --; ) {
LL x = read(), y = read();
cout << (solve(y) - solve(x - )) << "\n";
}
return ;
}
CF 55 D. Beautiful numbers的更多相关文章
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- CF D. Beautiful numbers (数位dp)
http://codeforces.com/problemset/problem/55/D Beautiful Numbers : 这个数能整除它的全部位上非零整数.问[l,r]之间的Beautifu ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...
- 【数位dp】CF 55D Beautiful numbers
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- Codeforces Beta Round #51 D. Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
- D. Beautiful numbers
题目链接:http://codeforces.com/problemset/problem/55/D D. Beautiful numbers time limit per test 4 second ...
随机推荐
- 【Python】opencv显示图像
import cv2 img = cv2.imread("lena.jpg") cv2.namedWindow("Image") cv2.imshow(&quo ...
- 【第三组】心·迹 Alpha版本 成果汇报
GITHUB地址 https://github.com/shirley-wu/HeartTrace 目录 项目简介 成果概要 详细展示(多图预警) 代码结构及技术难点 问题与规划 1. 项目简介 心· ...
- 从零自学Java-7.使用数组存储信息
1.创建数组: 2.设置数组的大小: 3.为数组元素赋值: 4.修改数组中的信息: 5.创建多维数组: 6.数组排序. 程序SpaceRemover:显示输入字符串,并将其中所有的空格字符替换为句点字 ...
- MySQL MTS复制: hitting slave_pending_jobs_size_max
测试步骤: 从库停止复制:stop slave; 主库创建大表400万条记录. 开启从库复制:start slave; 监测从库error log持续输出: 2018-12-06T10:40:52.6 ...
- seq 序列
seq 序列用法: seq [option]...last seq [option]...first last seq [option]...first increment last 例如:seq 5 ...
- Java 设计模式笔记
0. 说明 转载 & 参考大部分内容 JAVA设计模式总结之23种设计模式 1. 什么是设计模式 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设 ...
- selenium-键盘和鼠标事件
常见的键盘操作 from selenium.webdriver.common.keys import Keys 模拟enter键:send_keys(Keys.ENTER)键盘F1~F12: send ...
- Tidb进行缩减扩容tikv节点
这两天接到任务说是要进行测试缩减机器给集群带来的负面效果有哪些. 然后我就按照官方的教程将机器进行了缩减,主要是缩减tikv节点 我们先来看看官方的文章是怎么写的: 步骤都没有什么问题,就是进行到第二 ...
- CreateEvent
事件对象就像一个开关:它只有两种状态---开和关.当一个事件处于”开”状态,我们称其为”有信号”否则称为”无信号”.可以在一个线程的执行函数中创建一个事件对象,然后观察它的状态,如果是”无信号”就让该 ...
- 端口扫描--zmap
ZMap被设计用来针对整个IPv4地址空间或其中的大部分实施综合扫描的工具.ZMap是研究者手中的利器,但在运行ZMap时,请注意,您很有 可能正在以每秒140万个包的速度扫描整个IPv4地址空间 . ...