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
42
#include<cstdio>

long long int length(long long int x){
	long long int size = 0;
	while(x > 0){
		size++;
		x /= 10;
	}
	return size;
}

long long int k,a,b;
int squares[10] = {0,1,4,9,16,25,36,49,64,81};

long long int function(long long int n){
	long long int sum = 0;
	while(n > 0){
		sum+= squares[n%10];
		n /= 10;
	}
	return sum;
}

int main(){
	scanf("%lld %lld %lld", &k, &a, &b);
	long long int i = 0;
	long long int s = a%k?(a/k+1):(a/k);
	//printf("%lld\n", s);
	long long int g = b;
	long long int f = (k<=100000000000000LL)?(k*length(b)*81):(1000000000000000000LL);	
	//printf("%lld\n", f);
	long long int result = 0;
	long long int tmp = 0;
	for(i = s*k; i <= g && i <= f; i+=k){
		tmp = function(i)*k;
		if(tmp == i) {
			//printf("%lld\n", tmp);
			result++;
		}
	}
	printf("%lld\n", result);
}