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

public class row {
	private static int f(int n) {
		int sum = 0;
		do {
			int m = n%10;
			n = (n-m)/10;
			sum = sum + m*m;
		} while(n!=0);
		return sum;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt(); // k * f(n) = n
		int a = sc.nextInt(); // ograniczenie dolne a <=n
		int b = sc.nextInt(); // ograniczenie gorne n <= b
		sc.close();
		int l = 0; // liczba rozwiazan

		for(int n=a; n<=b;n++) {
			if(k*f(n)==n) {
				l++;
			}
		}
		System.out.println(l);
	}
}