题意:

如果一个数能被自己各个位的数字整除,那么它就叫 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. [SQL SERVER系列]读书笔记之SQL注入漏洞和SQL调优

    最近读了程序员的SQL金典这本书,觉得里面的SQL注入漏洞和SQL调优总结得不错,下面简单讨论下SQL注入漏洞和SQL调优. 1. SQL注入漏洞 由于“'1'='1'”这个表达式永远返回 true, ...

  2. office安装不了 “windows installer 服务不能更新一个或多个受保护的windows文件”

    出现这种情况可能是系统中某些文件缺失了,一般发生于安装GHOST版或做过精简的系统 打开C:\WINDOWS\msagent 看看文件夹中内容是不是如下图所示: 再打开C:\Program Files ...

  3. VB断点大全

    MultiByteToWideChar, ANSI字符串转换成Unicode字符串WideCharToMultiByte, Unicode字符串转换成ANSI字符串 //--------------- ...

  4. uva 10827

    与108类似 多加了两层循环 水过 #include <iostream> #include <cstring> #include <cstdio> #includ ...

  5. 定长内存池之BOOST::pool

    内存池可有效降低动态申请内存的次数,减少与内核态的交互,提升系统性能,减少内存碎片,增加内存空间使用率,避免内存泄漏的可能性,这么多的优点,没有理由不在系统中使用该技术. 内存池分类: 1.      ...

  6. 解析php中die(),exit(),return的区别

    die()停止程序运行,输出内容exit是停止程序运行,不输出内容return是返回值die是遇到错误才停止exit是直接停止,并且不运行后续代码,exit()可以显示内容.return就是纯粹的返回 ...

  7. 拒绝卡顿——在WPF中使用多线程更新UI

    原文:拒绝卡顿--在WPF中使用多线程更新UI 有经验的程序员们都知道:不能在UI线程上进行耗时操作,那样会造成界面卡顿,如下就是一个简单的示例: public partial class MainW ...

  8. IPC是什么意思?

    IPC(Inter-Process Communication,进程间通信)IPC ( Instruction per Clock 及CPU每一时钟周期内所执行的指令多少) IPC代表了一款处理器的设 ...

  9. *gravity的取值详表

    android有 android:layout_gravity 和 android:gravity,前者设置相对父控件布局,后者是设置自己内部的控件的布局. Value Description top ...

  10. Android开发之ADT导入Support Library

    在工程中增加(例如 support-v4 Library) 在ADT中需要按照以下步骤:  1.右击当前工程,查找Properties 2.选择Java Build Path 3.选择Librarie ...