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
66
67
68
69
70
#include <iostream>
using namespace std;

int ZM[10] = {1,3,5,7,9,11,13,15,17,-81};
typedef long long ll;

ll f(ll n)
{
	int sum = 0;
	int g;
	
	while(n!=0)
	{
		g = n%10;
		sum += g*g;
		n -= g;
		n /= 10;
	}
	return sum;
}

ll change(ll n)
{
	int k = 0;
	
	hop:
		int g = n%10;
		if(g != 9)
		{
 		 	 k += ZM[g];
			 return k;
		}
	
		n -= 9;
		n /= 10;
		
		if(n == 0) g = 0;
		
		k += ZM[9];
	goto hop;
}

int main()
{
	ll k, a, b;
	ll s = 0;
	
	cin >> k >> a >> b;
	
	ll p;
	p = f(a);
	if(k*p == a) s++;
	
	
	
	for(ll x = a+1; x <= b; x++)
	{
		if(x/k > 1458) break;
		p = p + change(x-1);
		
		if(x%k == 0)
		{
			if(p == x/k) s++;
		}
	}
	
	cout << s;
	
	return 0;
}