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
#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
#endif
#include <iostream>
using namespace std;

const long long MaxSum = 9*9*18;    // maksymalna suma kwadratow cyfr

int main() {
  ios_base::sync_with_stdio(0);

  int result = 0;
  long long min_value, max_value, k;
  
  cin >> k >> min_value >> max_value;
  max_value /= k;
  if(max_value > MaxSum)
    max_value = MaxSum;
  max_value *= k;

  for(; max_value >= min_value; max_value -= k) {
    int sum = 0;
    for(long long value = max_value; value > 0; value /= 10) {
      int c = value % 10;
      sum += c * c;
    }
    if(k * sum == max_value)
      ++result;
  }

  cout << result << endl;

  return 0;
}