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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <random>
#include <chrono>
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include <array>
#include <complex>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VP;
typedef vector<double> VD;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef long double ld;

#define MAXN 203
#define MAXN2 MAXN*MAXN
//#define MAXN 1006

string to_string(string s) {
	return '"' + s + '"';
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(bool b) {
	return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


const LL MOD = 1000000007;
//const LL MOD = 998244353;
//const LL INF = 2000000000000000001LL; //2e18 + 1

// From: https://community.topcoder.com/stat?c=problem_solution&rm=334707&rd=18191&pm=16406&cr=14970299
// LL ans = 0;
// iterate(1, N, [&](ll p1, int l1) -> void {
//   ans += ...;
// };
void iterate(LL from, LL to, function<void(LL, int)> process, int base = 10) {
	vector<LL> power;
	LL max = numeric_limits<LL>::max();
	power.push_back(1);
	while (max / power.back() >= base) {
		power.push_back(power.back() * base);
	}
	to++;
	for (int i = 0;; i++) {
		if (i != power.size() - 1 && from / power[i + 1] != to && from / power[i] % base == 0) {
			continue;
		}
		if (i != power.size() - 1 && from / power[i + 1] != to / power[i + 1] && from / power[i] % base != 0) {
			LL prefix = from / power[i + 1] * base;
			for (int j = (int)(from / power[i] % base); j < base; j++) {
				process(prefix + j, i);
			}
			from /= power[i + 1];
			from++;
			from *= power[i + 1];
		}
		else {
			LL upTo = to / power[i] % base;
			LL prefix = from / power[i] / base * base;
			for (int j = (int)(from / power[i] % base); j < upTo; j++) {
				process(prefix + j, i);
			}
			for (int k = i - 1; k >= 0; k--) {
				upTo = to / power[k] % base;
				prefix = to / power[k + 1] * base;
				for (int j = 0; j < upTo; j++) {
					process(prefix + j, k);
				}
			}
			break;
		}
	}
}

//LL dp[19][1 << 10][2521];
//int lcms[1<<10];
//LL p10[19];
/*
LL solve1(LL l, LL r) {
	LL ans = 0;
	iterate(l, r, [&](LL prefix, int len) -> void {
		int mask = 0;
		LL temp = prefix;
		while (temp) {
			if (temp % 10 == 0) {
				return;
			}
			mask |= (1 << (temp % 10));
			temp /= 10;
		}
		if ((mask & 1)) return;
		if (len == 0) {
			if (prefix % lcms[mask] == 0) {
				//debug(prefix, len, 1);
				ans++;
			}
			return;
		}
		LL sum = 0;
		for (int nmask = 0; nmask < (1 << 10); nmask += 2) {
			for (int k = 0; k < 2520; k++) {
				if ((prefix * p10[len] + k) % lcms[nmask | mask] == 0) {
					if (dp[len][nmask][k]) {
						sum += dp[len][nmask][k];
					}
				}
			}
		}
		//debug(prefix, len, sum);
		ans += sum;
	});
	return ans;
}
*/
int num[20];
LL memo[19][2][2521][1 << 9];
LL DP(int at, int less_or_eq/*0/1*/, int mod, int mask) {
	if (at == -1) {
		for (int i = 1; i < 10; i++) {
			if (mask & (1 << (i-1))) {
				if (mod % i) return 0;
			}
		}
		return 1;
	}
	LL&ret = memo[at][less_or_eq][mod][mask];
	if (ret != -1) return ret;

	ret = 0;
	for (int i = 1; i < 10; i++) {
		if (less_or_eq && i > num[at]) continue;
		int nxt_less_or_eq = (less_or_eq == 0 ? 0 : i == num[at]);
		ret += DP(at - 1, nxt_less_or_eq, (mod * 10 + i) % 2520, mask | (1 << (i - 1)));
	}
	return ret;
}

LL solve2(LL r) {
	if (r == 0) return 0;
	int at = 0;
	LL ans = 0;
	while (r) {
		num[at++] = r % 10;
		r /= 10;
	}
	MEM(memo, -1);
	ans += DP(at - 1, 1, 0, 0);
	for (int i = at - 2; i >= 0; i--) ans += DP(i, 0, 0, 0);
	return ans;
}

void solve(int ks) {
	LL l, r;
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	scanf("%lld %lld", &l, &r);
	//while (true) {
		//LL l = rng();
		//LL r = rng();
		//if (r < l) swap(l, r);
		//cerr << l << " " << r << endl;
		//LL ans1 = solve1(l, r);
		LL ans2 = solve2(r) - solve2(l - 1);
		//if (ans1 != ans2) {
			//cerr << l << " " << r << " " << ans1 << " " << ans2 << endl;
			//debug(l, r, ans1, ans2);
		//}
		//assert(ans1 == ans2);
	//}
	printf("%lld\n", ans2);
}
/*
void gen() {
	dp[0][0][0] = 1;
	p10[0] = 1;
	for (int i = 1; i <= 18; i++) {
		p10[i] = p10[i - 1] * 10;
	}
	for (int i = 0; i < 18; i++) {
		for (int j = 0; j < (1 << 10); j += 2) {
			for (int k = 0; k < 2520; k++) {
				for (int d = 1; d < 10; d++) {
					dp[i + 1][j | (1 << d)][(10 * k + d) % 2520] += dp[i][j][k];
				}
			}
		}
	}
	for (int mask = 0; mask < (1 << 10); mask += 2) {
		for (int i = 1; i <= 2520; i++) {
			int flag = 0;
			for (int j = 1; j < 10; j++) {
				if ((mask & (1 << j)) && (i % j)) flag = 1;
			}
			if (!flag) {
				lcms[mask] = i;
				break;
			}
		}
	}
}
*/
int main()
{
	double start_time = clock();
#ifdef LOCAL
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif

	//gen();

	if (0) {
		int T;
		scanf("%d", &T);
		//AIN(T, 1, 5000);
		for (int ks = 1; ks <= T; ks++) {
			solve(ks);
			//if (ks % 1 == 0) fprintf(stderr, "%d done\n", ks);
		}
	}
	else {
		solve(0);
	}

	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);

	return 0;
}