「CF55D」Beautiful numbers
2024-09-03 04:42:56
传送门
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\)
最新文章
- 北美IT公司大致分档
- Android SDK 镜像站
- hive函数参考手册
- 在Linux最小系统上编译运行第一个helloworld程序
- 昨日尝试使用百度死链提交,使用lCGI规则提交
- cannot change version web module 3.0
- Maven项目的发布,发布到Nexus
- [ActionScript 3.0] AS3动画类Tweener中滤镜的运用
- MySQL数据库乱码 - Linux下乱码问题一
- JDK PATH 和 CLASSPATH环境变量的作用及其配置
- Factorials 阶乘
- 使用SHA1、SHA2双证书进行微软数字签名
- C++中内存泄露的检测
- js 移动端识别手机号码
- 【其他】【http】【1】HTTP状态码
- (网页)web性能优化(转)
- easyui webapi
- MinGW下编译openssl, json-c
- Freemarker list的使用
- 所谓 A/B test