$CF55D [数位DP]$

数位DP+状压。
首先,按照数位DP的基本套路,每个个位数的最小公倍数为2520,所以只用考虑模2520的情况。考虑一个DP。dp[i][j][k]表示当前是第i位,2~9的数的集合为j,模2520为k的方案数。然后,就是数位DP的基本套路解决这道题。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read () {
LL res = ;
int f () ;
char ch = getchar ();
while (!isdigit(ch)) {
if (ch == '-') f = - ;
ch = getchar();
}
while (isdigit(ch)) res = (res << ) + (res << ) + (ch ^ ),ch = getchar();
return res * f ;
}
const int N=;
const int mod=;
int p[]= {,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,
};
int _lcm(int m,int n) {
return (m*n)/__gcd(m, n);
}
LL f[N][][mod+], bit[N], has[mod+];
inline LL dfs(int i,int lcm,int left, bool e) {
if(i==) return lcm&&left%p[lcm]== ;
if(!e && ~f[i][lcm][left]) return f[i][lcm][left];
LL ans=;
int u= e? bit[i]: ;
for(register int d=; d<=u; d++) {
int t= lcm? has[_lcm(p[lcm], max(d,))]: max(d,);
ans+=dfs(i-, t, (left*+d)%mod, e&&d==u);
}
return e==true? ans: f[i][lcm][left]=ans;
}
LL cal(LL n) {
int len=;
while(n) {
bit[++len]=n%;
n/=;
}
return dfs(len,,,true);
}
signed main() {
ios::sync_with_stdio(false);
memset(f,-,sizeof(f));
for(register int i=; i<; i++) has[p[i]]=i;
LL t=read();
while( t-- ) {
LL L=read(),R=read();
cout<<cal(R)-cal(L-)<<endl;
}
return ;
}

跑的好慢啊QwQ
随机推荐
- 国王游戏(codevs 1198)
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王站在队伍的最 ...
- CF585E:Present for Vitalik the Philatelist
n<=500000个2<=Ai<=1e7的数,求这样选数的方案数:先从其中挑出一个gcd不为1的集合,然后再选一个不属于该集合,且与该集合内任意一个数互质的数. 好的统计题. 其实就 ...
- Linux下汇编语言学习笔记42 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- linux 命令练习 2018-08-27
linux 命令练习 2018-08-27 uname 显示系统名字 [test@localhost ~]$ uname Linux uname -a 即列出linux的内核版本号 [test@ ...
- hdu_1398_Square Coins_201404260953
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Redis的集群方案之Sentinel(哨兵模式)(待实践)
哨兵模式是主从切换的一种方案,但是可以借助此方案实现集群,达到高可用. 先收集教程,待实践. 参考: https://redis.io/topics/sentinel(官方文档) http://ife ...
- [无线路由] “免费”斐讯K2路由器刷OpenWRT(实战MWAN多宽带网速叠加)
(阿财首发于什么值得买)斐讯K2可以算是一个非常另类的跨界数码产品,其产品完全的醉翁之意不在酒.最多值99元的 MT7260硬件架构和用料,售价399元,金额激活K码后自动转入合作理财P2P平台,等待 ...
- GNS3配置SecureCRT
C:\SecureCRT\SecureCRT.exe /script D:\GNS3\DyRouter.vbs /T /telnet 127.0.0.1 %p "D:\Program Fil ...
- CentOS firewall添加开放端口
添加 firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent永久生效,没有此参数重启后失效) 重新载入 firewal ...
- node-npm/yarn
很多人对npm或yarn了解甚少吧,下面我介绍一下常用的yarn/npm所谓的包管理工具. 首先我先介绍一下,npm属于国外Google镜像(下载贼慢),yarn属于Facebook开发的. npm: ...