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

using namespace std;

int main() {
    static long MAX = 18 * 81;
    long long k, a, b, x, n, d, r, res = 0;
    cin >> k >> a >> b;
    x = a / k;
    if (x * k < a){
        x++;
    }
    while (x * k <= b && x <= MAX){
        r = x;
        for (n = x * k; n > 0; n /= 10) {
            d = n % 10;
            r -= (d*d);
            if (r < 0){
                break;
            }
        }
        if (r == 0){
            res++;
        }
        x++;
    }
    cout << res << endl;
    return 0;
}