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 <cstdio>


int digs(long long n)
{
  int s = 0;
  while (n > 0)
  {
    int r = n % 10;
    s += r * r;
    n /= 10;
  }
  return s;
}

int main()
{
  long long k, a, b;
  
  scanf("%lld%lld%lld\n", &k, &a, &b);
  long long ret = 0;
  for (int i = 1; i <= 1600; i++)
  {
    long long n = k * i;
    if (n > b) break;
    if (n >= a)
    {
      if (i == digs(n))
      {
        //printf("%lld\n", n);
        ret++;
      }
    }
  }
  
	printf("%lld\n", ret);
	return 0;
	
}