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

 unsigned long long int ssum(unsigned long long int value)
 {
    unsigned long long int sum=0;
    while (value)
    {
        sum += (value % 10)*(value % 10);
        value=(value / 10);
    }
    return sum;
 }


 int main()
 {
 long long unsigned int k, a, b, sol=0;
    std::cin >> k;
    std::cin >> a;
    std::cin >> b;

    for (int i=0; i<=81*18; i++)
    {
        if (k*i < a) continue;
        if (k*i > b) break;
        if (ssum(k*i) == i) sol++;
    }

    std::cout << sol << std::endl;

 return 0;
 }