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
#include<bits/stdc++.h>
#define LL long long
#define FOR(x, b, e)  for(int x=b;x<=(e);x++)
using namespace std;
LL k,a,b,res;
LL f(LL x)
	{
	LL res=0;
	while(x)
		{
		res+=(x%10)*(x%10);
		x/=10;
		}
	return res;
	}
main()
{
cin>>k>>a>>b;
FOR(i,1,10000)
	{
	if(k*i<a)continue;
	if(b<k*i)break;
	if(f(k*i)==i)
		{
		res++;
		}
	}
cout<<res<<endl;
}