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
#include <stdio.h>


#define MAX_NUMBER 1500

int countSquareSum(long long int n){
	int sum = 0;
	while (n > 0){
		sum += (n % 10) * (n % 10);
		n = n / 10;
	}
	return sum;
}

int main(){
	long long int k, a, b;
	scanf("%lld %lld %lld", &k, &a, &b);
	long long int startPoint = a % k == 0 ? a : a + (k - a % k);
	int result = 0;
	for (long long int i = startPoint / k; i < MAX_NUMBER && startPoint <= b ; i++){
		if (countSquareSum(startPoint) == i){
			//printf("%lld\n", startPoint);
			result++;
		}
		startPoint += k;
	}
	printf("%d\n",result);
	return 0;
}