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


public class row {
	public static boolean czyK(long k, long x)
	{
		long x2=x;
		long pom;
		long y=0;
		while(x2!=0)
		{
			pom=x2%10;
			y = y+pom*pom;
			x2/=10;
		}
		if(y*k==x)return true;
		else return false;
	}
	public static void main(String[] args) {
		Scanner wejscie = new Scanner(System.in);
		long k = wejscie.nextLong();
		long a = wejscie.nextLong();
		long b = wejscie.nextLong();
		long ile=0;
		long temp=b-b%k;
		while(temp>=a)
		{
			if(czyK(k, temp)==true)ile++;
			temp-=k;
		}
		System.out.println(ile);
		wejscie.close();
	}

}