#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector> using namespace std; #define LL long long
const int MOD = ;
LL dp[][][];
int a[];
int Hash[]; LL gcd(LL a, LL b)
{
return b?gcd(b,a%b):a;
} LL dfs(int pos, int num, int lcm, bool limit)
{
if(-==pos) return num%lcm == ;
if(!limit && ~dp[pos][Hash[lcm]][num]) return dp[pos][Hash[lcm]][num];
LL ans = ;
int end = limit?a[pos]:;
for(int i=; i<=end; i++)
ans += dfs(pos-, (num*+i)%MOD, i?lcm*i/gcd(lcm,i):lcm, limit&&i==a[pos]);
if(!limit) dp[pos][Hash[lcm]][num] = ans;
return ans;
} LL solve(LL n)
{
int pos = ;
while(n)
{
a[pos++] = n%;
n /= ;
}
return dfs(pos-, , , );
} int main()
{
int T;
scanf("%d", &T);
int cnt = ;
for(int i=; i<=MOD; i++)
if(MOD%i == )
Hash[i] = cnt++;
memset(dp, -, sizeof(dp));
while(T--)
{
long long l, r;
scanf("%lld%lld", &l, &r);
printf("%lld\n", solve(r)-solve(l-));
}
return ;
}

A - Beautiful numbers的更多相关文章

  1. CodeForces 55D Beautiful numbers

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

  2. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

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

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

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

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

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

  6. CF 55D - Beautiful numbers(数位DP)

    题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...

  7. Codeforces Beta Round #51 D. Beautiful numbers

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

  8. Beautiful Numbers(牛客网)

    链接:https://ac.nowcoder.com/acm/problem/17385来源:牛客网 题目描述 NIBGNAUK is an odd boy and his taste is stra ...

  9. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  10. 【数位dp】Beautiful Numbers @2018acm上海大都会赛J

    目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...

随机推荐

  1. 5.JavaScript改变样式,验证用户输入

    ① x=document.getElementById("demo") //找到元素 x.style.color="#ff0000"; //改变样式 ② if ...

  2. 快速上手Ubuntu之安装篇——安装win7,Ubuntu16.04双系统【转】

    本文转载自:http://blog.csdn.net/qq_28205153/article/details/52203512 Linux可以说是开发者的系统,对于开发者来说,Linux发行版不仅为我 ...

  3. LightOJ1213 Fantasy of a Summation —— 快速幂

    题目链接:https://vjudge.net/problem/LightOJ-1213 1213 - Fantasy of a Summation    PDF (English) Statisti ...

  4. 让tomcat启动时,自动加载你的项目

    在tomcat-->conf-->serve.xml文件最后加上 <Context path="/atest" docBase="E:\Workspac ...

  5. legend2---开发日志12(vue如何进一步学习)

    legend2---开发日志12(vue如何进一步学习) 一.总结 一句话总结:还是得找教程(比如视频),自己摸索太浪费时间,也容易踩坑和抓不住重点 还是得找教程(比如视频),自己摸索太浪费时间,也容 ...

  6. hdu 1047 Integer Inquiry(大数)

    题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...

  7. Python: PS 滤镜--USM 锐化

    本文用 Python 实现 PS 滤镜中的 USM 锐化效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...

  8. 为什么在启动linux后进入终端提示sh-3.2#

    这是Linux系统环境变量设置问题,用户登陆后确保是root权限,可以用如下这两条命令解决:-bash-3.2# cp /etc/skel/.{bash_profile,bashrc} ~-bash- ...

  9. [APIO 2017] 商旅

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5367 [算法] 很明显的分数规划问题 预处理从一个点走到另一个点所获最大利润和最短路 ...

  10. TFS独占签出代码

    最近发现微软给我们提供了免费的TFS,地址:http://tfs.visualstudio.com/, 就注册了一个,但是我发现没办法独占签出. 在公司里,TFS有服务端,所以很好设置,但是注册微软的 ...