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学习笔记_JNI hello world
1.需要准备的工具,eclipse,cdt(c++)插件,cygwin(unix)和 android ndk. 在cygwin的etc目录下将ndk的路径引入到profile文件中,可以在cygwin ...
- postman发送HTTP请求自动生成MD5签名
POSTMAN是常用的接口测试工具 如何进行MD5签名呢? 代码如下: /** * 通过request.data获取body的内容,这个是postman内置变量 * 常用内置参数如下: * reque ...
- pdf.js 在线阅读PDF
在网上找了一下如何在线显示pdf文件.个人还是觉得这个是比较不错的,这里做一个记录. gitHub:https://github.com/mozilla/pdf.js 这是一个开源 ...
- webpack——安装报错及解决办法
①先删除 删除全局webpack-cli webpack4.x开始官方文档是说要安装cli所以如果的在用4.+就需要卸载cli npm uninstall -g webpack-cli # 注释给我这 ...
- vue2.0+node.js+mongodb全栈打造商城
Github地址:https://github.com/ccyinghua/vue-node-mongodb-project 一.构建项目所用: vue init webpack vue-node-m ...
- Struts2 第四讲 -- Struts2的基本配置
5.struts2的基本配置 5.1 struts2的访问连接url 在struts1中,通过<action path=“/primer/helloWorldAction.action”> ...
- TabbarController进行模块分类和管理
iOS-CYLTabBarController[好用的TabbarController] 用TabbarController进行模块分类和管理,这里推荐一个CYLTabBarController, ...
- 揭开redux,react-redux的神秘面纱
16年开始使用react-redux,迄今也已两年多.这时候再来阅读和读懂redux/react-redux源码,虽已没有当初的新鲜感,但依然觉得略有收获.把要点简单写下来,一方面供感兴趣的读者参考, ...
- ABAP术语-Data Transfer
Data Transfer 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/22/1048286.html The entire proces ...
- CentOS 7 以上防火墙简单配置
CentOS 7 版本以上默认的防火墙不是iptables,而是firewalle. 因此CentOS 7 以下的 iptables 的配置不能使用. 查看防火墙状态: systemctl statu ...