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
#include <iostream>
using namespace std;
bool czy_smkw(long long n, long long x)
{
	long long m = n*x, suma = 0;
	while(m > 0 && suma < n)
	{
		suma = suma + (m%10)*(m%10);
		m = m/10;
	}
	if(suma == n)
	{
	return 1;
}
	else
	return 0;
}
int main()
{
	int a, b, k, lic = 0;
	cin >> k >> a >> b;
	if(a%k != 0)
	{
	a = (a+k-(a%k))/k;
	}
	else
	a = a/k;

	b = (b-k+b%k)/k;
	while(a <= b)
	{
		if(czy_smkw(a, k))
		{
		lic++;
	}
		a++;
	}
	cout << lic;
	
}