传送门

Luogu

解题思路

毒瘤数位DP,发现一个前缀我们只需要记录它对 \(\operatorname{lcm}(1,2,3,\cdots,9)=2520\) 取模的值即可,所以我们在 DP 时记录一下当前的前缀模2520的值,以及前缀每一位数字的 \(\operatorname{lcm}\) 即可,至于空间的问题,只需要对2520的所有约数离散一下就好了。

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std; typedef long long LL; int a[20], xxx, mp[2520]; LL dp[20][2520][50]; inline LL dfs(int now, int las, int mod, int lim) {
if (!now) return las % mod == 0;
if (!lim && dp[now][las][mp[mod]] != -1) return dp[now][las][mp[mod]];
LL res = 0; int tp = lim ? a[now] : 9;
for (rg int j = 0; j <= tp; ++j)
res += dfs(now - 1, (las * 10 + j) % 2520, j == 0 ? mod : j * mod / __gcd(j, mod), lim && j == tp);
if (!lim) dp[now][las][mp[mod]] = res;
return res;
} inline LL solve(LL x) {
int n = 0;
for (rg LL i = x; i; i /= 10) a[++n] = i % 10;
return dfs(n, 0, 1, 1);
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
memset(dp, -1, sizeof dp);
for (rg int i = 1; i <= 2520; ++i)
if (2520 % i == 0) mp[i] = ++xxx;
int T; cin >> T;
for (LL l, r; T--; )
cin >> l >> r, cout << solve(r) - solve(l - 1) << endl;
return 0;
}

完结撒花 \(qwq\)

最新文章

  1. 北美IT公司大致分档
  2. Android SDK 镜像站
  3. hive函数参考手册
  4. 在Linux最小系统上编译运行第一个helloworld程序
  5. 昨日尝试使用百度死链提交,使用lCGI规则提交
  6. cannot change version web module 3.0
  7. Maven项目的发布,发布到Nexus
  8. [ActionScript 3.0] AS3动画类Tweener中滤镜的运用
  9. MySQL数据库乱码 - Linux下乱码问题一
  10. JDK PATH 和 CLASSPATH环境变量的作用及其配置
  11. Factorials 阶乘
  12. 使用SHA1、SHA2双证书进行微软数字签名
  13. C++中内存泄露的检测
  14. js 移动端识别手机号码
  15. 【其他】【http】【1】HTTP状态码
  16. (网页)web性能优化(转)
  17. easyui webapi
  18. MinGW下编译openssl, json-c
  19. Freemarker list的使用
  20. 所谓 A/B test

热门文章

  1. DataFrame loc和iloc的区别
  2. 《开课》---创业学习--训练营直播第一课--HHR
  3. Vue 项目 在局域网内访问
  4. VUE组件 单独文件封装
  5. 修改oracle数据库用户密码的方法
  6. DC-DC芯片
  7. excel表格 函数功能
  8. php 基础 获取远程连接
  9. faster-RCNN 加入新的Ground Truth
  10. 基于Goolgle最新NavigationDrawer实现全屏水平平移