题面

数位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

随机推荐

  1. POJ 3264 RMQ问题 用dp解决

    #include <cstdio> #include <cstring> #include <iostream> using namespace std; ; #d ...

  2. springboot 子模块访问不到对应的页面

    出现如下错误 解决方案 working directory:没有$MODULE_DIR$该选项,自己输入即可. 完成以上操作就可以正常访问页面了.

  3. 线程池之ThreadPool与ForkJoinPool

    网上对Java线程池都有很多非常具体的解析,我概念性进行总结下,如有错误,可与我联系修改. 1.1 ThreadPool Executor 一个线程池包括以下四个基本组成部分: 1.线程池管理器(Th ...

  4. JSP的表单处理

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/form-processing.html: 当需要从浏览器向Web服务器传递一些信息并最终将信息返回到后端 ...

  5. how to get geometry type of layer using IMapServer3 and IMapLayerInfo? (C#)

    http://forums.arcgis.com/threads/11481-how-to-get-geometry-type-of-layer-using-IMapServer3-and-IMapL ...

  6. StringBuffer疑问

    为何结果为AB.B? public static void main(String[] args) { StringBuffer a=new StringBuffer("A"); ...

  7. 简单区分iphone和ipad的宏定义

    在公共头文件里作例如以下定义: #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 使用时: if( IS_I ...

  8. Javascript基本概念梳理

    javascript里的数据类型: 原始类型:数字,字符串.布尔值.(原始值:null,undefined) 对象类型:键值对,数组,function,全局对象(MATH,JSON) 保留字: abs ...

  9. iOS开发----iOS 8的虚化效果

    在iOS 7中,一个重大的改变就是随处可见的虚化,这在通知中心和控制中心表现得尤为抢眼: 然而,当开发人员们着手去将类似的模糊效果增加自己的App的时候,他们会发现有相当严重的障碍. 那时苹果所界定的 ...

  10. 剑指offer面试题24-二叉搜索树的后序遍历序列

    题目: /*  * 输入一个整数数组,推断该数组是不是某二叉搜索树的兴许遍历的结果.<br/>  * 假设是则返回true,否则返回false.<br/>  * 如果输入的数组 ...