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 <bits/stdc++.h>

long long shit(long long l)
{
	long long res = 0;
	std::string s = std::to_string(l);
	int length = s.length();
	for(int i = 0; i < length; ++i)
		res += (int(s[i]-'0')*int(s[i]-'0'));
	return res;
}

int main()
{
	long long k, a, b;
	scanf("%lld%lld%lld", &k, &a, &b);
	
	long long gunwo;

	if(k >= a) gunwo = k;
	else gunwo = (k - a % k) + a;

	long long wyn = 0;

	for(long long i = gunwo; i <= b; i += k)
	{
		if(shit(i) == (i/k)) ++wyn; 
	}
	printf("%lld", wyn);
}