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

public class row{
    
    private static long computeSum(long number)
    {
        long sum = 0;
        while (true)
        {
            long leftover = number % 10;
            sum += leftover * leftover;
            if (number == leftover)
            {
                break;
            }
            number = (number - leftover) / 10;
        }
        
        return sum;
    }

     public static void main(String []args){
        Scanner scanner = new Scanner(System.in);
        
        long k = Long.parseLong(scanner.next());
        long a = Long.parseLong(scanner.next());
        long b = Long.parseLong(scanner.next());
        
        long counter = 0;
        
        for (long i = a; i <= b; i++)
        {
            if (k * row.computeSum(i) == i)
            {
                counter += 1;
            }
        }
        
        System.out.println(counter);
        
        return;
     }
}