CF 55D
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.
Input
The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two natural numbers li and ri (1 ≤ li ≤ ri ≤ 9 ·1018).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Output
Output should contain t numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from li to ri, inclusively).
Examples
1
1 9
9
1
12 15
2 数位dp。
在这道题中离散化是最关键的一步操作,不然dp数组占用内存过大,无法申请。
#include<cstdio>
#include<cstring> int shu[];
int lcm[];
long long dp[][][]; void init(){
memset(dp,-,sizeof(dp));
int cnt = ;
for(int i=;i<=;i++) // 离散化操作 将所有的因子处理出来
if(%i==)lcm[i]=++cnt;
//printf("%d\n",cnt); //
}
int gcd(int a, int b){
return b?gcd(b,a%b):a;
}
long long dfs(int k, int lc, int r, bool shangxian){
if(k==)return r%lc==;
if(!shangxian && dp[k][lcm[lc]][r]!=-)
return dp[k][lcm[lc]][r];
int maxn = shangxian?shu[k]:;
long long cnt = ;
for(int i=;i<=maxn;i++){
int now=lc;
if(i)
now *= i / gcd(i,lc);
cnt += dfs(k-,now,(r*+i)%,shangxian&&i==maxn);
}
return shangxian?cnt:dp[k][lcm[lc]][r]=cnt;
}
long long solve(long long x){
int k=;
while(x){
shu[++k] = x%;
x/=;
}
return dfs(k,,,);
}
int main(){
int t;
long long A, B;
init();
scanf("%d",&t);
while(t--){
scanf("%I64d %I64d",&A,&B);
printf("%I64d\n",solve(B)-solve(A-));
}
return ;
}
CF 55D的更多相关文章
- 数位DP CF 55D Beautiful numbers
题目链接 题意:定义"beautiful number"为一个数n能整除所有数位上非0的数字 分析:即n是数位所有数字的最小公倍数的倍数.LCM(1到9)=2520.n满足是252 ...
- CF 55D. Beautiful numbers(数位DP)
题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...
- CF 55D Beautiful numbers (数位DP)
题意: 如果一个正整数能被其所有位上的数字整除,则称其为Beautiful number,问区间[L,R]共有多少个Beautiful number?(1<=L<=R<=9*1018 ...
- cf 55D 数位dp 好题
/* 刚开始我考虑0的情况,想将他剔除就将lcmn设为-1,这样还要判断0和lcmn是-1的情况很麻烦而且但是一直出错 后来觉得不用管0的情况就行了,可以认为符合. 解:将lcmn离散化,因为1-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 (SPOJ JZPEXT 数位DP)
题意 求[X,Y]区间内能被其各位数(除0)均整除的数的个数. CF 55D 有些时候因为问题的一些"整体性"而导致在按位统计的过程中不能顺便计算出某些量,所以只能在枚举到最后一位 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
- 【转载】ACM总结——dp专辑
感谢博主—— http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 动态规划一 ...
随机推荐
- Android学习笔记_6_保存文件到SDCard
一.加入访问sdcard的权限 Environment.getExternalStorageState()方法用于获取SDCard的状态,如果手机装有SDCard,并且可以进行读写,那么方法返回的状态 ...
- hbase 数据拷贝
由于运营数据太大,另外避免影响正常访问,所以需要临时拷贝部分数据到临时表中. bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable [--star ...
- 安装 centos7
一.安装 省略前面安装操作,直接进入设置界面: 日期.键盘等设置按默认即可,主要是系统安装位置需要设置,点击 系统安装位置,进入设置 最终完成分区: 点击左上角完成按钮 接受更改 开始安装 设置roo ...
- MVVM及框架的双向绑定
MVVM由以下三个内容组成 View:视图模板 Model:数据模型 ViewModel:作为桥梁负责沟通View和Model,自动渲染模板 在JQuery时期,如果需要刷新UI时,需要先取到对应的D ...
- 开发工具--Eclipse使用及常见问题解决
怎么查询Eclipse版本号: 方法一: 方法二: Eclipse安装目录下面找到readme文件夹,里边有个网页打开就可以看到当前版本; Eclipse汉化改为英文: Eclipse Mybatis ...
- Linux常用文档操作命令--1
1.查看目录下的文档 a) ls(list):查看目录下的所有文档或者文档的信息. 命令行:ls [-a][-A] [-f][-F][-h][-l][-r][-R][-S][-t] 目录名称 //注 ...
- 中间件kafka
* kafka----一个发布订阅消息系统,中间件:一个分布式.分区.可重复的日志服务kafka需要了解基础几层结构,生产者订阅者等使用方法,和在高并发.一致性场景使用.(凡事面试问一致性.高并发都脱 ...
- Hadoop(10)-HDFS的DataNode详解
1.DataNode工作机制 1)一个数据块在DataNode上以文件形式存储在磁盘上,包括两个文件,一个是数据本身,一个是元数据包括数据块的长度,块数据的校验和,以及时间戳. 2)DataNode启 ...
- mysql导出数据库表名与字段信息
一.导出数据库表格信息 #mysql导出库的表格信息 SELECT A.TABLE_SCHEMA, A.TABLE_NAME, A.TABLE_ROWS, A.CREATE_TIME, A.TABLE ...
- 005---Python数据类型--字典
字典 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px ...