#P5991. Multiplicative Digit Square Sum Equation

    ID: 19216 Type: Default 1000ms 256MiB

Multiplicative Digit Square Sum Equation

Multiplicative Digit Square Sum Equation

For a positive integer \( n \), define \( \operatorname{f}(n) \) as the sum of the squares of its digits in decimal. Given three positive integers \( k, a, b \), count the number of integers \( n \) such that \( a \le n \le b \) and \( k\times \operatorname{f}(n) = n \).

More formally, find the number of \( n \) in \( [a,b] \) satisfying \[ k \times \left(\sum_{\text{digit } d \text{ of } n} d^2\right) = n. \]

inputFormat

The input consists of a single line containing three positive integers \( k, a, b \) separated by spaces.

outputFormat

Output a single integer representing the number of integers \( n \) within the range \( [a,b] \) that satisfy \( k\times \operatorname{f}(n) = n \).

sample

1 1 100
1