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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// PA 2015, miodziu@poczta.fm

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#define mp make_pair

int read() { int n; scanf("%d", &n); return n; }
char readc() { char c; scanf("%c", &c); return c; }
LL readl() { LL n; scanf("%lld", &n); return n; }

#define REP(i,n) for (int i=0,_=(n); i<_; ++i)
#define FOR(i,a,b) for (int i=(a),_=(b); i<=_; ++i)
#define FORD(i,a,b) for (int i=(a),_=(b); i>=_; --i)

#define st first
#define nd second



const int MAX_F = 20 * 9 * 9;

int f(LL n) {
    int res = 0;
    for (; n>0; n/=10) {
	int d = n % 10;
	res += d * d;
    }
    return res;
}

int solve(LL k, LL a, LL b) {
    int res = 0;
    LL x = a / k;
    for (; k*x<=b && x<MAX_F; ++x) {
	if (k * x < a) continue;
	if (x == f(k * x)) {
	    //printf("%lld\n", k * x);
	    res++;
	}
    }
    return res;
}

int main() {
    LL k = readl();
    LL a = readl();
    LL b = readl();
    printf("%d\n", solve(k, a, b));
    return 0;
}