1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
#include <cstdint>
using namespace std;

uint64_t digit_sum(uint64_t x) {
	uint64_t sum = 0;
	while (x) {
		sum += (x % 10) * (x % 10);
		x /= 10;
	}
	return sum;
}

int main() {
	uint64_t k, a, b;
	scanf("%llu %llu %llu", &k, &a, &b);
	uint64_t c = 0;
	for (uint64_t i = a; i <= b; ++i)
		if (k * digit_sum(i) == i)
			++c;
	printf("%llu", c);
	return 0;
}