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
#include <iostream>
using namespace std;
bool isValid(const long long number);
int main() {
	long long from, to;
	cin >> from;
	cin >> to;
//	cout << "start " << from << " " << to << endl; // prints start
	long long counter = 0;
	for (long long i = from; i < to; i++) {
//		cout << i << ": ";
		const bool valid = isValid(i);
		if (valid) {
			counter++;
		}
//		cout << (valid ? " TAK" : " NIE");
//		cout << endl;
	}
	cout << counter << endl; // prints start
	return 0;
}

bool isValid(const long long number) {
	const int D = 10;
	bool digits[D] = { false };
	long long val = number;
	while (val > 0) {
		digits[val % D] = true;
		val = val / D;
	}
//	for (int i = 0; i < D; ++i) {
//		if (digits[i]) {
//			cout << i;
//		}
//	}
	bool valid;
	if (digits[0]) {
		valid = false;
	} else {
		valid = true;
		for (int p = 1; p < D; ++p) {
			if (digits[p]) {
				if (number % p != 0) {
					valid = false;
					break;
				}
			}
		}

	}

	return valid;
}