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
36
37
38
39
#include <iostream>
#include <stack>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int fun(int n){
	stack<int> digits;
	int part = 0;
	int result = 0;
	while(n>=1){
		digits.push(n%10);
		n=n/10;
	}
	while(digits.size()>0){
		part=digits.top();
		digits.pop();
		result +=part*part;
	}
	return result;
}
int main(int argc, char** argv) {
	int k, a, b;
	cin>>k>>a>>b;
	int temp=0;
	int en=0;
	int min=0, max=0;
	min = k;
	max = k*1458;
	for(int i=0; i<=1458; i++){
		if(i*k>=a && i*k<=b){
			if(i == fun(i*k)){
			temp++;
			}
		}
	}
	cout<<temp;
	
	return 0;
}