题面

数位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. ZOJ 3329 期望DP

    题目大意: 给定3个已经规定好k1,k2,k3面的3个色子,如果扔到a,b,c则重新开始从1 计数,否则不断叠加所有面的数字之和,直到超过n,输出丢的次数的数学期望 我们在此令dp[]数组记录从当前数 ...

  2. MTK TP手势添加

    old: #include "tpd.h" #include "tpd_custom_gt9xx.h" #ifndef TPD_NO_GPIO #include ...

  3. [NOIP2006] 提高组 洛谷P1066 2^k进制数

    题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后 ...

  4. Nginx配置文件nginx.conf 详解

    #定义Nginx运行的用户和用户组 user www www;   #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8;   #全局错误日志定义类型,[ debu ...

  5. javaSctipt基础

    ===================================== JavaScript 脚本语言===================================== 什么是JavaSc ...

  6. POJ 3083_Children of the Candy Corn

    题意: 给定迷宫图,求出一个人从入口进,从出口出,所走过的最短路径以及分别沿着左手边和右手边的墙走出迷宫所走过的方格数. 分析: bfs求最短路 对于沿左右两边的墙走的情况,记录好行走的方向及相对应的 ...

  7. MongoDB小结06 - update【$push】

    数组修改器,既然名字都这样叫了,那么这个修改器就只能对数组进行操作啦. db.user.update({"name":"qianjiahao"},{" ...

  8. Hdoj 3697 Selecting courses 【贪心】

    Selecting courses Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others ...

  9. js类继承扩展super

    相应的资料https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/super 例子: class Pol ...

  10. Sping框架的IOC特性 悲观锁、乐观锁 Spring的AOP特性

    Sping框架的IOC特性 IOC(Inversion of Control):控制反转 以下以课程与老师的安排来介绍控制反转. 一个合理的课程编排系统应该围绕培训的内容为核心,而不应该以具体的培训老 ...