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的更多相关文章

  1. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  2. CF D. Beautiful numbers (数位dp)

    http://codeforces.com/problemset/problem/55/D Beautiful Numbers : 这个数能整除它的全部位上非零整数.问[l,r]之间的Beautifu ...

  3. CF 55D - Beautiful numbers(数位DP)

    题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...

  4. 【数位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 ...

  5. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  6. 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 ...

  7. Codeforces Beta Round #51 D. Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  8. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

  9. D. Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D D. Beautiful numbers time limit per test 4 second ...

随机推荐

  1. react native中的聊天气泡以及timer封装成的发送验证码倒计时

    今天看来情书写的文章,研究了一下大佬写的文章,自己做一点总结. 其实,今天我想把我近期遇到的坑都总结一下:1.goBack的跨页面跳转,又两种方法,一可以像兔哥那样修改navigation源码,二可以 ...

  2. 【Python】定时调度

    from datetime import datetime from apscheduler.schedulers.blocking import BlockingScheduler def tick ...

  3. Appium环境搭建python篇(mac系统)

    1.安装Appium 通过终端安装: 安装nodejs,下载地址:https://nodejs.org/download/,安装完成后打开终端输入node -v,检查是否安装成功 安装npm,打开终端 ...

  4. SQL Server 跨网段(跨机房)通过备份文件初始化复制

    笔者最近碰到了需要搭建跨网段的SQL Server复制,实际的拓扑结构如下草图所示: 发布端A服务器位于CDC机房中 订阅端B服务器位于阿里云 因为SQL Server复制不支持通过IP连接分发服务器 ...

  5. Python Socket传输文件

    发送端可以不停的发送新文件,接收端可以不停的接收新文件. 例如:发送端输入:e:\visio.rar,接收端会默认保存为 e:\new_visio.rar,支持多并发,具体实现如下: 接收端: 方法一 ...

  6. DAU、UV、独立IP、PV的区别和联系

    基本概念 DAU(Daily Active User)日活跃用户数量.常用于反映网站.互联网应用或网络游戏的运营情况.DAU通常统计一日(统计日)之内,登录或使用了某个产品的用户数(去除重复登录的用户 ...

  7. swift的类型约束

    关键词: 类型与功能绑定.类型指定.访问控制. 类型约束的本质: 1.是否强制指定具有某些特征的类型:看类型构造器的定义本身是否对类型有约束: 2.访问控制:类型构造器的功能分为通用功能和约束功能: ...

  8. 关于Maven配置的一些标签含义(后续逐渐补充)

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. 【转】通过blob获取图像并显示

    HTML代码: <div id="forAppend" class="demo"></div> JS代码: var eleAppend ...

  10. Spark项目之电商用户行为分析大数据平台之(二)CentOS7集群搭建

    一.CentOS7集群搭建 1.1 准备3台centos7的虚拟机 IP及主机名规划如下: 192.168.123.110 spark1192.168.123.111 spark2192.168.12 ...