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
#include<iostream>
#include<vector>

using namespace std;

long long f(long long n)
{
    long long s = 0;
    while(n)
	{
        s += (n % 10) * (n % 10);
        n /= 10;
	}
	return s;
}

vector<long long> V;

int main()
{
	ios_base::sync_with_stdio(0);
	long long k, a, b;
	cin >> k >> a >> b;
	for (long long i = 1; i <= 1458 and k * i <= b; i++) if (k * f(k * i) == k * i) V.push_back(k * i);
	int cnt = 0;
	for (int i = 0; i < V.size(); i++) if (a <= V[i] and V[i] <= b) cnt++;
	cout << cnt << "\n";

	return 0;
}