原题链接

虽然依旧是套模板,但是因为我太弱了,不会建状态,所以去看了题解。。

这里就直接引用我看的题解吧,写的不错的。

题解

//我的代码
#include<cstdio>
#include<cstring>
using namespace std;
const int mod = 2520;
const int N = mod + 10;
typedef long long ll;
int a[20], lc[N], l;
ll f[20][N][50];
inline ll re()
{
ll x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
int gcd(int x, int y)
{
if (!y)
return x;
return gcd(y, x % y);
}
int LCM(int x, int y)
{
if (!y)
return x;
return x / gcd(x, y) * y;
}
ll dfs(int pos, int nw, int lcm, int lm)
{
if (pos < 0)
return nw % lcm ? 0 : 1;
if (!lm && f[pos][nw][lc[lcm]] > -1)
return f[pos][nw][lc[lcm]];
int i, k = lm ? a[pos] : 9;
ll s = 0;
for (i = 0; i <= k; i++)
s += dfs(pos - 1, (nw * 10 + i) % mod, LCM(lcm, i), lm && i == a[pos]);
if (!lm)
return f[pos][nw][lc[lcm]] = s;
return s;
}
ll calc(ll x)
{
int k = 0;
do
{
a[k++] = x % 10;
x /= 10;
} while (x > 0);
return dfs(k - 1, 0, 1, 1);
}
int main()
{
int i, t;
ll n, m;
for (i = 1; i * i <= mod; i++)
if (!(mod % i))
{
lc[mod / i] = ++l;
lc[i] = ++l;
}
memset(f, -1, sizeof(f));
t = re();
for (i = 1; i <= t; i++)
{
n = re();
m = re();
printf("%I64d\n", calc(m) - calc(n - 1));
}
return 0;
}

最新文章

  1. swift 判断字符串长度
  2. Linux system函数详解
  3. [AHOI2013]找硬币(搜索)
  4. 每日一九度之 题目1030:毕业bg
  5. WebStorm 对 Mocha 完美支持。
  6. win7 开启休眠
  7. MySQL架构优化实战系列2:主从复制同步与查询性能调优
  8. Linux Bash终端支持中文显示
  9. Ubuntu_16.04_Lamp
  10. Linux中kettle启动spoon.sh遇到的问题
  11. Docker系列一之基础快速入门企业实战
  12. javascript中的时间版运动
  13. 开放windows服务器端口-----以打开端口8080为例
  14. GMM算法的matlab程序
  15. JQ面向对象的放大镜
  16. nvidia驱动自动更新版本后问题解决 -- failed to initialize nvml: driver/library version mismatch
  17. C语言数据结构基础学习笔记——静态查找表
  18. 性能监控扩展篇(grafana + influxdb + telegraf)
  19. EntityFramework 基础提供程序在 Open 上失败
  20. Linux中ls -l(ll)返回结果中的文件访问权限-rw-r--rw-

热门文章

  1. Applese的毒气炸弹-最小生成树Kruskal算法
  2. android Zxing 扫描区域的大小设置和自定义扫描view
  3. 如何区分Java中的方法重载和重写
  4. hello world讲解1
  5. veil-catapult
  6. python 分词
  7. Java LinkedList
  8. python3获得命令行输入的参数
  9. CSS clip:rect矩形剪裁功能及应用
  10. js常用返回网页顶部几种方法