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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class row {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] params = input.readLine().split(" ");
        input.close();

        long k = Long.parseLong(params[0]);
        long a = Long.parseLong(params[1]);
        long b = Long.parseLong(params[2]);
        long count = 0;
        for(long i=a/k;i<= Math.min(b/k, 1377);i++) {
            if(i ==  digitPowSum(i*k)) {
                count++;
            }
        }
        System.out.println(count);
    }

    private static long digitPowSum(long src) {
        long sum = 0;
        char[] chars = Long.toString(src).toCharArray();
        for(char ch : chars) {
            int value = Character.getNumericValue(ch);
            sum += value * value;
        }
        return sum;
    }
}