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. Python数据类型之list和tuple

    list是一种有序的集合,可以随时添加和删除其中的元素. 用len()函数可以获得list元素的个数. 用索引来访问list中每一个位置的元素,索引是从0开始的.如果要取最后一个元素,除了计算索引位置 ...

  2. 在 Azure Resource Manager 中为虚拟机设置密钥保管库

    Note Azure 具有两种不同的部署模型,用于创建和处理资源:Resource Manager 模型和经典模型.本文介绍使用 Resource Manager 部署模型.Azure 建议对大多数新 ...

  3. mysql主从不同步问题 Error_code: 1197

    首先查看从的状态   mysql> show slave status \G *************************** 1. row *********************** ...

  4. Relinking Oracle Home FAQ ( Frequently Asked Questions) (Doc ID 1467060.1)

    In this Document   Purpose   Questions and Answers   1)  What is relinking ?   2)  What is relinking ...

  5. jQuery Validate 介绍

    jQuery Validate jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方 ...

  6. Linux内核同步机制之completion【转】

    Linux内核同步机制之completion 内核编程中常见的一种模式是,在当前线程之外初始化某个活动,然后等待该活动的结束.这个活动可能是,创建一个新的内核线程或者新的用户空间进程.对一个已有进程的 ...

  7. October 16th 2017 Week 42nd Monday

    The more decisions that you are forced to make alone, the more you are aware of your freedom to choo ...

  8. 2018.09.01 09:22 Exodus

    Be careful when writing in the blog garden. Sometimes you accidentally write something wrong, and yo ...

  9. 【转】为什么Github没有记录你的Contributions

    【转】为什么Github没有记录你的Contributions 字数985 阅读0 评论0 喜欢0 记录下为什么github 提交的时候,没有记录到 github 的那个日历上。 Paste_Imag ...

  10. Asp.Net WebApi服务的创建

    Web API一种REST架构风格的Web服务.所谓的REST架构与技术无关,而是面向资源的一种软件架构设计. WCF自3.5之后也提供了对REST风格的支持,但和WebAPI来比较显得较为笨重,We ...