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
40
41
42
43
44
45
46
47
48
49
#include <cstdlib>
#include <iostream>
#include <sstream>

using namespace std;

long long squares[] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100};
long long k = 0;
long long a = 0;
long long b = 0;
long long n2;
int digit = 0;
int result = 0;
stringstream digits;

int main(int argc, char *argv[])
{
    cin >> k;
    cin >> a;
    cin >> b;

    for (long long n=a; n <= b; n++) {
        n2 = 0;
        digits.clear();
        digits.str("");

        digits << n;

        for (int i=0; i < digits.str().size(); i++) {
                digit = static_cast<int>(digits.str().at(i)) - 48;

                if (n2 == 0) {
                        n2 =  squares[digit];
                } else {
                        n2 += squares[digit];
                }
        }

        n2 = k * n2;

        if (n == n2) {
                result++;
        }
    }

    cout << result;

    return EXIT_SUCCESS;
}