题目链接:http://codeforces.com/problemset/problem/55/D

题意:求区间[L,R]有多少个Beautiful numbers。Beautiful numbers为能被组成该数字的各个数字整除的数字。

思路:由于所有1-9数字的Lcm为2520。我们用f[i][j][k]表示到达第i位,前面的数字模2520的余数为j,前面数字的Lcm为k,那么最后j%k=0即可。

i64 n,m;int a[20],num;
int mp[2600];
i64 f[20][2600][55][2];
int cnt;void init()
{int i;FOR1(i,N) if(N%i==0) mp[i]=++cnt;
}int Gcd(int x,int y)
{if(!y) return x;return Gcd(y,x%y);
}int Lcm(int x,int y)
{if(y==0) return x;return x*y/Gcd(x,y);
}i64 DFS(int dep,int flag,int allZero,int mod,int lcm)
{if(dep==-1) return mod%lcm==0&&!allZero;if(!flag&&f[dep][mod][mp[lcm]][allZero]!=-1) return f[dep][mod][mp[lcm]][allZero];int Max=flag?a[dep]:9;int i;i64 ans=0;for(i=0;i<=Max;i++){ans+=DFS(dep-1,flag&&i==Max,allZero&&i==0,(mod*10+i)%2520,Lcm(lcm,i));}if(!flag) f[dep][mod][mp[lcm]][allZero]=ans;return ans;
}i64 cal(i64 x)
{if(x<=9) return x;num=0;while(x){a[num++]=x%10;x/=10;}return DFS(num-1,1,1,0,1);
}int main()
{init(); clr(f,-1);rush(){scanf("%I64d%I64d",&n,&m);printf("%I64d\n",cal(m)-cal(n-1));}
}

CodeForces - 55D Beautiful numbers相关推荐

  1. Codeforces 55D Beautiful numbers (数位DP)

    题意:有T组询问,每次询问区间[l, r]中的beautiful number有多少.beautiful number是指这个数可以被组成它的数字整除.例如15是beautiful number,因为 ...

  2. 数位DP CF 55D Beautiful numbers

    题目链接 题意:定义"beautiful number"为一个数n能整除所有数位上非0的数字 分析:即n是数位所有数字的最小公倍数的倍数.LCM(1到9)=2520.n满足是252 ...

  3. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  4. CF 55D Beautiful numbers 数位DP

    思路: 要找一个数能被他的所有反的数字整除,只需求出这个数能被其数字的LCM整除.而LCM最大为5*7*8*9=2520: 如果直接开dp[20][2520][2520]会超内存,而2^3,3^2,5 ...

  5. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  6. Codeforces Beta Round #51 D. Beautiful numbers 数位dp + 状态优化

    传送门 文章目录 题意: 思路: 题意: 思路: 数位dpdpdp挺经典的一个题辣,有一个很明显的状态就是f[pos][num][lcm]f[pos][num][lcm]f[pos][num][lcm ...

  7. D. Beautiful numbers

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

  8. 【CodeForces 1265C --- Beautiful Regional Contest】

    [CodeForces 1265C --- Beautiful Regional Contest] 题目来源:点击进入[CodeForces 1265C - Beautiful Regional Co ...

  9. CodeForces 893B Beautiful Divisors (打表)

    题目大意:最近,Luba了解了一种特殊的数字,他称之为"漂亮的数字".这个数被称为漂亮是因为它的二进制表示包括k+1个连续的,然后是k个连续的0. Some examples of ...

最新文章

  1. mysql 5.6 主从同步配置_Mysql 5.6主从同步配置
  2. Uboot配置界面详解
  3. [EF Core]数据迁移(二)
  4. 模型设计器工具控件LinqConnect
  5. [密码学基础][每个信息安全博士生应该知道的52件事][Bristol52]42蒙哥马利乘法,哪里泄漏侧信道路吗?
  6. 摆胯教学分解_聚十年求索,筑理想课堂——厦门市梧侣学校十周年庆区级教学小学数学(数与形)...
  7. linux用grep查找包含两个关键字的命令
  8. Java MVC框架性能比较
  9. Html之实例练习(轮播图片、放大镜效果、面板拖动)
  10. DevExpress学习03——label控件的背景色问题
  11. html show指定显示什么,Dialog show() 方法 定义和用法_HTML对象
  12. iOS Expected unqualified-id 和 Unkown type name 'NSString'
  13. python 趋势线计算式_[原创]图表趋势线公式系数的计算公式
  14. 羲云社区团购微信小程序多门店版,首页开发
  15. 如何查看centos系统版本以及配置信息
  16. 火星坐标系解密-iDesktopX空间数据处理
  17. LabWindows/CVI入门之第二章:GUI开发
  18. Spring5-完全注解开发【之】第一步,先实现功能(增删改查),再讲解陌生代码
  19. 跟谁学 英语口语20090927疑问句
  20. “实名认证”与“实人认证”该怎么选?

热门文章

  1. 《51单片机应用开发从入门到精通》——2.2 跑马灯实例
  2. CentOS 7 yum源安装Nginx
  3. HTML5 Audio标签方法和函数API介绍
  4. 线程池的一些疑问和解答
  5. Javascript将构造函数扩展为简单工厂
  6. Android开源测试框架
  7. ADO.NET—数据提供程序(连接类)
  8. Google 选择 Jetty 放弃 Tomcat
  9. 使用redisson时关于订阅数的问题
  10. Java中的异常和递归