1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
const long long MN = 1000000000;
const long long MAXN = MN * MN;
long long f(long long n) {
    if (n == 0)
        return 0;
    int c = n % 10;
    return c * c + f(n / 10);
}

int main() {
    long long k, a ,b;
    int s = 0;
    scanf("%lld%lld%lld", &k, &a, &b);
    for (long long n = ((a - 1) / k + 1) * k; n <= b && n <= MAXN; n += k) {
        if (f(n) * k == n) {
            //printf("%d\n", n);
            s++;
        }
    }
    printf("%d", s);
    return 0;
}