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

public class row {
	
	private static BigInteger f(BigInteger n) {
		int res = 0;
		BigInteger tmp = n;
		BigInteger ten = new BigInteger("10");
		while(tmp.compareTo(BigInteger.ZERO)>0) {
			int digit = tmp.mod(ten).intValue();
			res += digit*digit;
			tmp = tmp.divide(ten);
		}
		return BigInteger.valueOf(res);
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		BigInteger k = in.nextBigInteger();
		BigInteger a = in.nextBigInteger();
		BigInteger b = in.nextBigInteger();
		in.close();
		
		BigInteger begin = a.divide(k).multiply(k);
		if(begin.compareTo(k)<0)
			begin = begin.add(k);
		BigInteger end = k.multiply(new BigInteger("1380"));
		if(b.compareTo(end)<0)
			end = b;
		
		int counter = 0;
		for(BigInteger i=begin;i.compareTo(end)<0;i = i.add(k)) {
			if(k.multiply(f(i)).equals(i))
				counter++;
		}
		
		System.out.println(counter);
	}

}