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
#include <stdio.h>
#include <vector>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <cmath>

#define ULL64 unsigned long long int

using namespace std;


ULL64 sqsum(ULL64 x)
{
	ULL64 ret = 0;
	while(x>0)
	{
		ret+=((x%10)*(x%10));
		x/=10;
	}
	return ret;
}

int main()
{

	ULL64 k,a,b;
	scanf("%llu %llu %llu",&k,&a,&b);

	ULL64 ret = 0;
	ULL64 upperBound = 1458<b/k ? 1458:b/k;

	for(ULL64 fn = 1;fn<=upperBound;fn++)
	{
		if((k*fn>=a && k*fn<=b) && (k*fn == k*sqsum(k*fn)))
		{
			ret++;
		}
	}
	
	printf("%llu\n",ret);

	return 0;
}