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
#include <cstdio>
typedef long long LL;
LL x,a,b,k;
int wynik;
int f(LL xx)
{
	int res=0,c;
	while(xx>0)
	{
		c=xx%10;
		res+=(c*c);
		xx/=10;
	}
	return res;
}
int main()
{
	scanf("%lld%lld%lld", &k, &a, &b);
	for(int i=1; i<1500; ++i)
	{
		if(((b/i)+2)<k)
			break;
		x=k*i;
		if(x<=b && x>=a)
		{
			if(f(x)==i)
				++wynik;
		}
	}
	printf("%d", wynik);
}