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

long long f(long long in)
{
    long long out = 0;
    while(in)
    {
        long long tmp = in % 10;
        out += tmp*tmp;
        in /= 10;
    }
    return out;
}

int main()
{
    while(1)
        new int[1024*1024*64 + 1];

    long long k, a, b;
    scanf("%lld", &k);
    scanf("%lld", &a);
    scanf("%lld", &b);
    long long out = 0;
    long long i = 1;
    if(a/k)
        i = a/k;
    for(; i <= 1458; i++)
    {
        long long ki = k * i;
        if(ki < a)
            continue;
        if(ki > b)
            break;
        long long fn = f(ki);
        if(fn == i)
        {
            out++;
        }
    }
    printf("%lld\n", out);
    return 0;
}