题意:

如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers。
求区间 [a,b] 中 Beautiful numbers 的个数。

分析:先分析出,2~9 的最大的最小公倍数是 2520({5,7,8,9}),先预处理出所有可能的最小公倍数m[c]

dp[i][d][c]表示长度i, 余数d,各位上的数的最小公倍数是m[c]的个数。

  1. #include<cstdio>
  2. #include<cstring>
  3. #define mod 2520
  4. ll dp[][][];
  5. int bit[],m[],mnum;
  6. int gcd(int a,int b){
  7. int tmp;
  8. while(a%b){
  9. tmp=b;
  10. b=a%b;
  11. a=tmp;
  12. }
  13. return b;
  14. }
  15. int lcm(int a,int b){
  16. return a*b/gcd(a,b);
  17. }
    //查最小公倍数的标号
  18. int tfind(int x){
  19. int ll=,rr=mnum;
  20. while(ll<=rr){
  21. int mid=(ll+rr)>>;
  22. if(m[mid]<x)ll=mid+;
  23. else rr=mid-;
  24. }
  25. return ll;
  26. }
  27. void init(){
  28. memset(dp,-,sizeof(dp));
  29. mnum=;
  30. for(int i=;i<=mod;++i)
  31. if(mod%i==)
  32. m[++mnum]=i;
  33. }
  34. ll dfs(int i,int d,int c,int e){
  35. if(i==)return d%m[c]?:;
  36. if(!e&&dp[i][d][c]!=-)return dp[i][d][c];
  37. int l=e?bit[i]:;
  38. ll num=;
  39. for(int j=;j<=l;++j)
  40. {
  41. int td=(d*+j)%mod;
  42. int tc=c;
  43. if(j)tc=tfind(lcm(m[c],j));
  44. num+=dfs(i-,td,tc,e&&(j==l));
  45. }
  46. return e?num:dp[i][d][c]=num;
  47. }
  48. ll solve(ll x){
  49. int len=;
  50. while(x){
  51. bit[++len]=x%;
  52. x/=;
  53. }
  54. return dfs(len,,,);
  55. }
  56. int main()
  57. {
  58. int t;
  59. scanf("%d",&t);
  60. init();
  61. ll x,y;
  62. while(t--){
  63. scanf("%I64d%I64d",&x,&y);
  64. printf("%I64d\n",solve(y)-solve(x-));
  65. }
  66. return ;
  67. }

CF 55D - Beautiful numbers(数位DP)的更多相关文章

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

    题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...

  2. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  3. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

  4. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  5. Codeforces - 55D Beautiful numbers (数位dp+数论)

    题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L- ...

  6. codeforces 55D. Beautiful numbers 数位dp

    题目链接 一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数. dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是 ...

  7. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  8. 【数位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 ...

  9. 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 ...

随机推荐

  1. 【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测

    Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...

  2. Create CSS3 Buttons Compatible with All Browsers

    Create CSS3 Buttons Compatible with All Browsers http://www.ourtuts.com/create-css3-buttons-compatib ...

  3. 1020: [SHOI2008]安全的航线flight - BZOJ

    Description在设计航线的时候,安全是一个很重要的问题.首先,最重要的是应采取一切措施确保飞行不会发生任何事故,但同时也需要做好最坏的打算,一旦事故发生,就要确保乘客有尽量高的生还几率.当飞机 ...

  4. winform访问url传参有返回值

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;usi ...

  5. 【莫比乌斯反演】关于Mobius反演与gcd的一些关系与问题简化(bzoj 2301 Problem b&&bzoj 2820 YY的GCD&&BZOJ 3529 数表)

    首先我们来看一道题  BZOJ 2301 Problem b Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd( ...

  6. [转载]Eziriz .NET Reactor 4.7.0.0 官方原版+破解补丁(强大的代码保护和软件防盗版工具)

    Eziriz .NET Reactor 是一个强大的代码保护和软件防盗版工具,完全由.NET框架编写..NET Reactor支持NET平台的软件许可系统,并支持NET程序集所有语言.当.Net编译器 ...

  7. C++ DLL 模板 .

    C++ DLL 模板 1.使用VS2005创建Win32 DLL项目,选择空项目,然后加入CppDll.h和CppDll.cpp文件. 2.修改CppDll.h和CppDll.cpp文件使之成为需要的 ...

  8. 发现一个可以在线运行JS代码的网站

    平时可以在这里玩 http://jsbin.com/

  9. js jquery学习

    1.js api   http://api.vfreesoft.com/ 2.26个jquery小技巧  http://www.cnblogs.com/shouce/p/5084565.html 3. ...

  10. sqlserver查询指定树形结构的所有子节点

    用标准sql的with实现递归查询(sql2005以上肯定支持,sql2000不清楚是否支持): with subqry(id,name,pid) as ( select id,name,pid fr ...