1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	long long a,b,k,t;
	int f,l,r=0;
	cin>>k>>a>>b;
	b /= k;
	for(long long i = (a+k-1)/k; i <= b; i++){
		t=i*k;
		f=0;
		while(t){
			l  = t%10;
			f += l*l;
			t /= 10;
		}
		if(f == i)
			r++;
	}
	cout<<r<<endl;
	return 0;
}