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
#include <iostream>
using namespace std;

int f (int x)
{
    static int power_array[] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81};
    int result = 0;
    while (x != 0)
    {
        result += power_array[x%10];
        x = x/10;
    }
    return result;
}

int main ()
{
    int a, b, k;
    cin >> k >> a >> b;
    int counter = 0;
    
    int n = a;
    for (int i = a/k; n <= b ; ++i)
    {
        n = k*i;
        if (f(n) == i)
            ++counter;  
    }
    
    cout<<counter;
    return 0;
}