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

using namespace std;

long long func(int n)
{
    int sumaKwadratow = 0;
    while(n > 0)
    {
        sumaKwadratow += (n%10)*(n%10);
        n /= 10;
    }

return sumaKwadratow;
}

int main()
{

    int k, a, b;
    cin >> k >> a >> b;
    int wynik = 0;

    for(int n = a; n <= b; n++)
    {
        if(n % k == 0)
        {
            if(n/k == func(n))
            {
                wynik++;
            }
        }
    }

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