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
#include <iostream>

int SumSquares(long long n) {
  int res = 0;
  while (n > 0) {
    int d = n%10;
    res += d*d;
    n /= 10;
  }
  return res;
}

int Solve(long long k, long long a, long long b) {
  int res = 0;
  for (int sum = 0; sum <= 18 * 9 * 9; ++sum) {
    long long n = k * sum;
    if (n > b) break;
    if (n >= a && SumSquares(n) == sum) ++res;
  }
  return res;
}

int main() {
  long long k, a, b;
  std::cin >> k >> a >> b;
  std::cout << Solve(k, a, b) << '\n';
}