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
#include <iostream>
typedef unsigned long long ull;

unsigned f(ull n)
{
    //oblicza sume kwadratow cyfr liczby n
    unsigned result = 0;
    while(n > 0)
    {
        unsigned d = n % 10;
        result += d*d;
        n /= 10;
    }
    return result;
}

int main()
{
    ull a, b, n, k;
    unsigned ans = 0;
    unsigned maxf = 1458;
    std::ios_base::sync_with_stdio(0);
    std::cin>>k>>a>>b;
    ull t = 1000000000000000000 / k;
    if (t < maxf)
        maxf = t;
    for(unsigned i = 1; i <= maxf; ++i)
    {
        n = k * i;
        if(n >= a && n <= b && f(n) == i)
            ++ans;
    }
    std::cout<<ans;

	return 0;
}