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.*;
 
public class row
{
	private static long[] squares = {0,1,4,9,16,25,36,49,64,81};
    public static void main(String[] argv)
    {
		Scanner s = new Scanner(System.in);
		argv = s.nextLine().split(" ");
        long k= Long.parseLong(argv[0]);
        long a = Long.parseLong(argv[1]);
        long b = Long.parseLong(argv[2]);
        long n = (a/k) * k;
        long count = 0;
        for(; n < b; n=n+k)
        {
            if( k*sumaKwadratow(n) == n)
            {
                ++count;
            }
        }
        System.out.println(count);
    }

    private static long sumaKwadratow(long n)
    {
        int sum = 0;
        while(n > 0)
        {
            sum += squares[(int)(n%10)];
            n=n/10;
        }
        return sum;
    }
}