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

public class row {
	
	public static void main(String[] z) throws IOException {
		BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
		String line = bi.readLine();
		StringTokenizer tokenizer = new StringTokenizer(line);
		long k = Long.parseLong(tokenizer.nextToken());
		long a = Long.parseLong(tokenizer.nextToken());
		long b = Long.parseLong(tokenizer.nextToken());
		long ileSpelnia = 0;
		for (long n = a; n<=b; n++)
			if (czyLiczbaSpelniaRownanie(k, n))
				ileSpelnia++;
		PrintWriter drukuj = new PrintWriter(new BufferedOutputStream(System.out));
		drukuj.println(ileSpelnia);
		drukuj.flush();
	}

	public static long f(long n){
		long wynik = 0;
		while(n != 0){
			long cyfra = n%10;
			wynik += cyfra*cyfra;
			n /= 10;
		}
		return wynik;
	}
	
	public static boolean czyLiczbaSpelniaRownanie(long k, long n){
		return f(n)*k == n;
	}
}