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
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;

LL digitSquaresSum(LL n) {
	LL ret = 0;
	while (n > 0) {
		ret += (n%10) * (n%10);
		n /= 10;
	}
	return ret;
}

LL solve(LL mx, LL k) {
	LL ret = 0;
	for (LL i = 0; i < 1800; i++) {
		LL n = i * k;
		if (n <= mx) {
			if (digitSquaresSum(n) == i) ret++;
		}
	}
	return ret;
}

int main() {
	LL k, a, b;
	scanf("%lld%lld%lld", &k, &a, &b);
	printf("%lld\n", solve(b, k) - solve((a-1), k));
	
	
	return 0;
}