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
44
#include <iostream>
#include <string>
#include <cstdio>


using namespace std;


long long f(long long x) {
    long long s = 0;
    do {
        s += (x % 10) * (x % 10);
    } while (x /= 10);
    return s;
}

int main() {
   
    long long _k, _a, _b;
    long long k, a, b;
    string line;

    
    getline(cin, line);
    
    sscanf(line.c_str(), "%lld %lld %lld", &_k, &_a, &_b);


    k = _k;
    a = _a + _k - (_a%_k);
    b = _b - (b%_k);
        
    int ret = 0;
    while (a <= b) {
        if (f(a) == a / k) {
            ret++;
        }
        a += k;
    }
    
    cout << ret << endl;

    return 0;
}