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
#include<stdlib.h>
#include<stdio.h>
#include<algorithm>
#include<iostream>

typedef unsigned long long ULL;
int tab[1500];
ULL sosod(ULL n)
{
	std::cerr << "sosod " << n;
	ULL x=0;
	while (n)
	{
		x+=(n%10)*(n%10);
		n/=10;
	}
        std::cerr << " " << x << '\n';
	return x;
}

int main()
{
        ULL k,a,b,up;
        scanf("%llu%llu%llu",&k,&a,&b);
        up = std::min(b/k,1458ULL);
	for(int i=1;i<=up;i++)
		if(sosod(i*k)==i)tab[i]=tab[i-1]+1;
		else tab[i]=tab[i-1];
	printf("%d\n",tab[b/k]-tab[(a-1)/k]);
        return 0;
}