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

typedef long long int llint;

llint f(llint n){
	llint w = 0;
	while(n>0){
		int c = n%10;
		w += c*c;
		n /= 10;
	}
	return w;
}


int main()
{
	llint k, a, b;
	
	std::cin >>  k >>  a >> b;
	
	llint start = a/k, 
	      stop = b/k,
		  i = start;
	llint n = start * k;
	if(n<a) {
	    i++;
		n += k;
	}
	
	int count = 0;
	while(i <= stop) {
		if( f(n) == i ) {
			//std::cout << n << " " << i << " " << f(n) << "\n";
			count++;
		}
		n += k;
		i++;		
	}
	std::cout << count; 
}