题目
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.
Input
The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two natural numbers li and ri (1 ≤ \li≤ ri≤ 9 ·1018).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Output
Output should contain t numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from li to ri, inclusively).
Examples
Input
1
1 9
Output
9
Input
1
12 15
Output
2
解析
数位dp
离散
dp形式为dp[a][b][c]
a为数位
b为当前数字
c为组成这个数字的因子的最大公倍数(为了节省空间)
思路
具体框架还是数位dp那一套。
dp大小为dp[30][2520+10][50]
数位30很好理解
数字大小是2520是因为2520是1到9的最小公倍数。因为这个位置的数字是为了表示这个数字是什么,但是数字会过大,所以我们只要表示成因子和它一样的数字就行了,所以只需要控制在2520中就行了。
第三个数字 50,这个位置的数字是为了表示我们递归到这个位置的时候,这个数字可以被什么数字整除,所以就可以表示成这些数字的最大公因数,所以按道理来说范围也应该是2520,但是超范围了。于是我们要操作下。我们可以发现,这些数字组成的公因数(也就是2520的因子)是有限的,大概50个,我们映射下就行。
这里明白了就很好写了,下面附上代码。
代码
#include<bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxn=1