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

using namespace std;
std::vector<long long> potegi = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81};

bool isOK(long long n)
{
    long long tmpCounter = 0, tmpN = n;
    while(tmpN)
    {
        tmpCounter = tmpCounter + potegi[tmpN % 10];
        tmpN = tmpN/10;
    }
    if(tmpCounter == n)
        return true;
    else
        return false;
}

int main()
{
    long long k, a, b;
    std::cin >> k >> a >> b;
    for (auto& it: potegi)
    {
        it = it * k;
    }
    long long n = a, counter = 0;
    for(; n <= b; n++)
    {
        if(isOK(n))
        {
            counter++;
        }
    }
    std::cout << counter;
    return 0;
}