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
#include <cstdio>
#include <cstdlib>

typedef unsigned long long num_t;

#define TAB_SIZE 19
static num_t a;
static num_t b;
static num_t k;

num_t fn(char* x) {
    num_t sum = 0;
    size_t i = 0;
    while (x[i]) {
        char c = x[i] - '0';
        sum += (c * c);
        i++;
    }
    return sum;
}

int main(int argc, char* argv[]) {
    scanf("%llu %llu %llu\n", &k, &a, &b);
    num_t count = 0;
    for (num_t x = a; x <= b; ++x) {
        static char buff[TAB_SIZE];
        sprintf(buff, "%llu", x);
        num_t fnv = fn(buff);
        if (x == fnv * k) {
            count++;
        }
    }
    printf("%llu\n", count);
    return 0;
}