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
#include <iostream>

using namespace std;

//	Very important constant
const long long limit = 18 * 81;

long long f(long long number) {
	long long result = 0;

	while (number > 0) {
		int digit = number%10;
		result += digit*digit;
		number /= 10;
	}

	return result;
}

int main() {
	ios_base::sync_with_stdio(false);

	long long k, a, b;
	cin >> k >> a >> b;

	if (a > b) {
		cout << 0 << endl;
		return 0;
	}

	int counter = 0;

	for (long long i = 1; i <= limit && i <= b/k; ++i) {
		if (i*k < a)
			continue;

		if (f(i*k) == i)
			counter++;
	}

	cout << counter << '\n';

	return 0;
}