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

using namespace std;

const unsigned long long maxf = 9 * 9 * 18;

int powers[] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81};

unsigned long long f(unsigned long long n) {
    unsigned long long sum = 0;
    while (n) {
        unsigned int dig = n % 10;
        sum += powers[dig];
        n /= 10;
    }
    return sum;
}

int main()
{
   unsigned long long k, a, b;
   cin >> k >> a >> b;
   
   
   unsigned long long result = 0;
   
   for (unsigned long long i = a; i <= b; ++i) {
       if (i % k != 0)
        continue;
       
       if (i > k * maxf)
        break;
       
       if (i == k * f(i)) {

           ++result;
       }
   }
   
   cout << result;
   
   return 0;
}