1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 2*3*2*5*7*2*3, L = 20, D = 9;
ll dp[L][(1<<D)][mod], pow10[L];
ll Lcm(ll x, ll y) {
	if(x==0 || y==0) return 0;
	return x / __gcd(x, y) * y;
}
int mem[(1<<D)];
int get_prod(int mask) {
	if(mem[mask]!=0) return mem[mask];
	int res = 1;
	for(int i=0; i<D; ++i) {
		if(mask&(1<<i)) {
			res = Lcm(res, i+1);
		}
	}
	mem[mask] = res;
	return res;
}
ll get(ll x) {
	if(x==0) return 0;
	ll ans = 0;
	vector<int> dig;
	while(x) dig.push_back(x%10), x/=10;
	int n = dig.size();
	int pref = 0, pref_prod = 1;
	for(int i=n-1; i>=0; --i) {
		for(int j=0; j<(1<<D); ++j) {
			if(i>0) for(int k=0; k<mod; ++k) if(get_prod(j)!=0 && k%get_prod(j)==0) ans += dp[i][j][k];
			int mprod = get_prod(j);
			for(int d=0; d<dig[i]-1; ++d) {
				int prod = Lcm(mprod, Lcm(pref_prod, (d+1)));
				for(int k=0; k<mod; k++) {
					if(prod!=0 && (k+pref+(d+1)*pow10[i])%prod==0) {
						ans += dp[i][j][k];
					}
				}
			}
		}
		pref = (pref+dig[i]*pow10[i])%mod;
		pref_prod = Lcm(pref_prod, dig[i]);
	}
	if(pref_prod!=0 && pref%pref_prod==0) ans++;
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	pow10[0] = 1;
	for(int i=1; i<L; ++i) {
		pow10[i] = (pow10[i-1]*10)%mod;
	}
	dp[0][0][0] = 1;
	for(int i=1; i<L; ++i) {
		for(int j=0; j<(1<<D); ++j) {
			for(int d=0; d<D; ++d) {
				for(int k=0; k<mod; k++) {
					dp[i][(j|(1<<d))][(k+(d+1)*pow10[i-1])%mod] += dp[i-1][j][k];
				}
			}
		}
	}
	ll l, r; cin>>l>>r;
	cout<<get(r) - get(l-1);
}