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
#include <iostream>
using namespace std;

long long potegi[18];

bool sprawdz (long long n) {
	long long pom=n;
	while (n>0) {
		short x = n%10;
		if (pom%x!=0) return false;
		n /= 10;
	}
	return true;
}


int main() {
	ios_base::sync_with_stdio(0);
	long long cn = 0; potegi[0] = 10;
	for (int i=1; i<18; ++i) potegi[i] = potegi[i-1]*10;
	long long l, r; cin>>l>>r;
	while (l<r) {
		if (sprawdz(l)) cn++;
		l++;
		for (int i=17; i>=0; --i) {
			if (l%potegi[i]==0) l += potegi[i]/10;
		}
	}
	cout<<cn;
}