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>
typedef long long int LL;

int f(LL n) {
    int result = 0;
    while (n > 0) {
        result += (n%10)*(n%10);
        n /= 10;
    }
    return result;
}

int main() {
    LL k, a, b;
    scanf("%Ld%Ld%Ld", &k, &a, &b);
    
    int result = 0;
    for (LL sum=0; sum<=18*9*9; sum++)
        if (k*sum >= a && k*sum <= b && f(k*sum) == sum)
            result++;

    printf("%d\n", result);
}