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

unsigned long long int value(unsigned long long int x){
	unsigned long long int base = 10;
	unsigned long long int sum = 0;
	unsigned long long int zero = 0;
	while(x != zero){
		unsigned long long int digit = x % base;
		sum += digit * digit;
		x /= base;
	}
	return sum;
}

unsigned long long k, a, b, next_number, result;
int main(){
	cin >> k >> a >> b;
	next_number = 0;
	result = 0;
	for(unsigned long long int i = 0; i < 1500; ++i){
		next_number += k;
		if(next_number < a){
			continue;
		}
		if(next_number > b){
			break;
		}
		if(k * value(next_number) == next_number){
			++result;
		}
	}
	cout << result << endl;
	return 0;
}