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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

vector <long long int> wyniki;

long int fun(long long int x)
{
	int tab[20], l = 0;
	fill (tab, tab + 20, 0);
	long int w = 0;
	while(x != 0)
	{
		tab[l] = x % 10;
		l++;
		x = x / 10;
	}
	for (int i = 0; i < l; i++)
	{
		w += tab[i] * tab[i];
	}
	return w;
}

int main()
{
	long long int k, a, b;
	scanf ("%lld", &k);
	scanf ("%lld", &a);
	scanf ("%lld", &b);
	
	long long int maks, h;
	int pot = 1;
	for (int i = 10; pot <= 18; i *= 10)
	{
		h = i / k;
		//cout << h << " " << pot*82 << endl;
		if (h < pot * 82)
			pot++;
		else
		{
			maks = h + 3;
			break;
		}
	}
	long long int c;
	long long int d = b / k;
	if (a % k == 0) c = a / k;
	else c = a / k + 1;
	if (d > maks) d = maks;
	//cout << c << " " << d << endl;
	while (c <= d)
	{
		if (fun(c * k) == c)
			if(a <= k * c && b >= k * c)
			wyniki.push_back(c * k);
		c++;
	}
	//for (int i = 0; i < wyniki.size(); i++)
	//	cout << wyniki[i] << endl;
	
	printf("%lld", wyniki.size());
	return 0;
}