题意:

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

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

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

#include<cstdio>
#include<cstring>
#define mod 2520
ll dp[][][];
int bit[],m[],mnum;
int gcd(int a,int b){
int tmp;
while(a%b){
tmp=b;
b=a%b;
a=tmp;
}
return b;
}
int lcm(int a,int b){
return a*b/gcd(a,b);
}
//查最小公倍数的标号
int tfind(int x){
int ll=,rr=mnum;
while(ll<=rr){
int mid=(ll+rr)>>;
if(m[mid]<x)ll=mid+;
else rr=mid-;
}
return ll;
}
void init(){
memset(dp,-,sizeof(dp));
mnum=;
for(int i=;i<=mod;++i)
if(mod%i==)
m[++mnum]=i;
}
ll dfs(int i,int d,int c,int e){
if(i==)return d%m[c]?:;
if(!e&&dp[i][d][c]!=-)return dp[i][d][c];
int l=e?bit[i]:;
ll num=;
for(int j=;j<=l;++j)
{
int td=(d*+j)%mod;
int tc=c;
if(j)tc=tfind(lcm(m[c],j));
num+=dfs(i-,td,tc,e&&(j==l));
}
return e?num:dp[i][d][c]=num;
}
ll solve(ll x){
int len=;
while(x){
bit[++len]=x%;
x/=;
}
return dfs(len,,,);
}
int main()
{
int t;
scanf("%d",&t);
init();
ll x,y;
while(t--){
scanf("%I64d%I64d",&x,&y);
printf("%I64d\n",solve(y)-solve(x-));
}
return ;
}

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. Python之print语句

    print语句可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print 'hello, world' 注意: 1.当我们在Python交 ...

  2. C#跳出循环的几种方法的区别

    break是循环结束执行,执行循环体后面的代码. continue是跳过本次循环未执行的代码,继续执行下一次循环. goto是跳到指定的指令去,你指哪,他跳到哪. return是函数返回,如果循环在M ...

  3. ACCESS数据库操作教程

    网易学院视频教程: 上:http://tech.163.com/06/0621/17/2K5K0C2200091U6J.html中:http://tech.163.com/06/0621/17/2K5 ...

  4. Samza的ApplicationMaster

    当Samza ApplicationMaster启动时,它做以下的事情: 通过STREAMING_CONFIG环境变量从YARN获取配置信息(configuration) 在随机端口上 启动一个JMX ...

  5. Head First 设计模式笔记:单例模式

    单例模式 确保一个类只有一个实例,并提供一个全局访问点. 类图: Singleton static uniqueInstance //其他属性... static getInstance() //其他 ...

  6. mysql学习链接

    1 传智播客PHP培训.刘道成.PHP视频教程.mysql http://down.51cto.com/zt/887

  7. Win7 默认hosts文件

    # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP f ...

  8. LinkedList源代码深入剖析

    第1部分 LinkedList介绍LinkedList简介 public class LinkedList<E> extends AbstractSequentialList<E&g ...

  9. POJ2506——Tiling

    Tiling Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a samp ...

  10. CentOS7 64位 自动分配IP地址设置

    vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 # ifcfg-后接网卡名称 配置如下,ONBOOT设置为yes HWADDR=:0C::E9 ...