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
import java.util.Scanner;

public class row {
    private static final int NINE_SQUARE = 9*9;
    private static final short[] data = new short[19];

    public static int initialize(long n) {
        for (int i = 0; i < data.length; i++)
            data[i] = 0;

        int sum = 0;
        int i = 0;
        while (n != 0) {
            short a = (short) (n % 10);
            n /= 10;

            data[i++] = a;
            sum += a*a;
        }

        return sum;
    }

    public static int calculateNext(int sum) {
        int i = -1;
        do {
            i++;
            int last = data[i];
            data[i]++;
            if (data[i] == 10) {
                data[i] = 0;
                sum -= NINE_SQUARE;
            } else {
                sum += (data[i] * data[i]) - (last * last);
            }

        } while(data[i] == 0 && i < data.length);

        return sum;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long k = scanner.nextLong();
        long a = scanner.nextLong();
        long b = scanner.nextLong();

        int count = 0;
        int sum = initialize(a);
        if (sum * k == a)
            count++;
        for (long i = a + 1; i <= b; i++) {
            sum = calculateNext(sum);
            if (sum * k == i)
                count++;
        }

        System.out.println(count);
    }
}