1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdio>

inline long long sum(long long x) {
    int res = 0;
    while(x) {
        res += (x % 10) * (x % 10);
        x /= 10;
    }
    return res;
}

int main() {
    int res = 0;
    long long a, b, k;
    scanf("%lld%lld%lld", &k, &a, &b);
    long long n = (a + k - 1) / k * k;
    while(n / k < 1400 && n <= b) {
        if(sum(n) == n / k)
            res++;
        n += k;
    }
    printf("%d\n", res);
    return 0;
}