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
#include<bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<=(e);i++)
#define FORD(i,s,e) for(int i=(s);i>=(e);i--)
#define ALL(k) (k).begin(),(k).end()
#define e1 first 
#define e2 second
#define MP make_pair
#define PB push_back 
#define EB emplace_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<int,PII> PIP;

LL f(LL x){
	LL wyn=0;
	while(x>0){
		wyn+=(x%10)*(x%10);
		x/=10;
	}
	return wyn;
}

main(){
	LL k,a,b;scanf("%lld%lld%lld",&k,&a,&b);
	LL ans=0;
	for(LL i=0;i<=20111;i++){
		if(k*i>b) break;
		LL z=k*i;
		if(f(z)!=i) continue;
		if(a<=z&&z<=b) ans++;
	}
	printf("%lld\n",ans);
}