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

using namespace std;

const int inf = 2020000020;
const int N = 200200;
long long a[20];
long long b[20][20];
long long t[1<<20][20];

bool ok(long long a, int b) {
    int s = 0;
    while(a) {
        int t = a%10;
        s += t*t;
        a /= 10;
    }
    return s == b;

}
int main()
{

    long long k,a,b;
    cin >> k >> a >> b;
    int mx = min(2000LL, b/k);
    int ret = 0;
    for(int i=1;i<=mx;++i) {
        long long w = k*i;
        if (w < a) continue;
        if (w > b) break;
        ret += ok(w,i);
    }
    cout << ret << endl;

    return 0;
}