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
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

long squaresum(long number)
{
	long wyn = 0;
	for (int i = (int) log10(number) + 1; i>-1; i--) {
		wyn += (long)pow(((number / (long)pow(10, i)) - (number / ((long)pow(10, i + 1))) * 10), 2);
	}
	return wyn;
}

long numberofnumbers(long k, long a, long b){
	long non = 0;
	long w = 0;
	for (long i = 0;; i += k)
		if (i >= a && i <= b){
			w = i;
			break;
		}
		else if (i>b)
			return 0;
	for (long i = w; i<b + 1; i += k)
		if (squaresum(i) == i / k){
			non++;
		}
	return non;
}

int main(string args[]){
	long k;
	cin >>k;
	long a;
	cin >>a;
	long b;
	cin >>b;
	
	cout << numberofnumbers(k,a,b) << endl;
	
	system("PAUSE");

	return 0;
}