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

using namespace std;

int f(long long n) {
	int res = 0;
	while (n) {
		int x = n % 10;
		res += x*x;
		n /= 10;
	}

	return res;
}

long long g(long long a, long long b, long long k) {
	long long res = 0;

	if (a % k != 0)
		a += k - a % k;

	while (a <= b) {
		if (f(a)*k == a) ++res;
		if (a / k > 9 * 9 * 18) break;
		a += k;
	}
	return res;
}

int main(int argc, char* argv[]) {
	long long k, a, b;

	cin >> k >> a >> b;

	cout << g(a, b, k) << endl;

	return 0;
}