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 ...
随机推荐
- Djang之Model操作
Django之Model操作 一.字段 1.字段列表: AutoField(Field) - int自增列,必须填入参数 primary_key=True BigAutoField(AutoField ...
- [SQLSERVER] 把TransactionLog截断
注意:以下语句非常危险 --BACKUP LOG MyDb TO DISK=’NUL:’
- 异常System.BadImageFormatException
[问题描述] Server Error in '/' Application. Could not load file or assembly 'WebDemo' or one of its depe ...
- C# System.IO.Path
Path的常用方法 函数列表 对一个路径做相应操作,包括文件路径,目录路径,通常会用到Path这个类, 本文列举一些常用的操作. 获取指定路径字符串的目录信息 public static string ...
- Windows DHCP备份还原命令
DHCP服务器如果要更换,最简单的方法就是命令导入导出 导出netsh dhcp server export e:\dhcp.txt all 导入netsh dhcp server import ...
- jQuery插件实例六:jQuery 前端分页
先来看看效果: 对于前端分页,关键是思路,和分页算法.本想多说两句,可又觉得没什么可说的,看代码吧: 如何使用? $("#pging").zPagination({ 'navEve ...
- elasticsearch之JAVA环境变量报错:could not find java; set JAVA_HOME or ensure java is in PATH
在以RPM包安装elasticsearch过程中出现报错JAVA环境的问题: ● elasticsearch.service - Elasticsearch Loaded: loaded (/usr/ ...
- MySQL主从复制半同步复制原理及搭建
在MySQL5.5之前的版本中,MySQL的复制是异步复制,主库和从库的数据之间存在一定的延迟,比如网络故障等各种原因,这样子容易存在隐患就是:当在主库写入一个事务成功后并提交了,但是由于从库延迟没有 ...
- .net core 入坑经验 - 1、await async
已经有些日子没学习新知识了,心血来潮想试试core有多大变化和跨平台运行 所以现在就开始捣鼓,然而由于是从.net 4.0直接"跃升"到.net core 以及 asp.net m ...
- Spring Boot session与cookie的使用
Session import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import ...