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

using namespace std;

int main()
{
    unsigned long long int k, a, b;
    unsigned long long int tab[10] = {0,1,4,9,16,25,36,49,64,81};
    cin>>k>>a>>b;
    unsigned long long int q;
    if(k < 100000000000000)
    {
        q = k * 1458;
        if(q<b)
            b=q;
    }
    unsigned long long int pocz = a - (a % k);
    if(pocz < a)
        pocz += k;
    unsigned long long int wynik=0, ile, num, x;
    for(unsigned long long int i=pocz; i<=b; i+=k)
    {
        num = i;
        ile = 0;
        while(num > 0)
        {
            x = num % 10;
            ile += tab[x];
            num /= 10;
        }
        if(ile == i/k)
            wynik++;

    }
    cout<<wynik<<endl;
    return 0;
}