#P1822. Lucky Numbers Based on Magic Fingerprint
Lucky Numbers Based on Magic Fingerprint
Lucky Numbers Based on Magic Fingerprint
For any positive integer \(n\) with at least two digits, define \(\mathrm{magic}(n)\) as follows: write \(n\) in base 10, and then for each pair of adjacent digits, write down the absolute difference. Concatenate these differences to form a new number, and remove any leading zeros. In particular, if \(n\) is a single digit then \(\mathrm{magic}(n)=n\).
For example: \(\mathrm{magic}(5913)=482\), \(\mathrm{magic}(1198)=081=81\), \(\mathrm{magic}(666)=00=0\).
For any number \(n\), repeatedly apply \(\mathrm{magic}\) to generate a sequence: \([ n,\;\mathrm{magic}(n),\;\mathrm{magic}(\mathrm{magic}(n)),\;\ldots ]\). The final one-digit number is called the magic fingerprint of \(n\>.
For example, for \(n=5913\), the sequence is \([5913, 482, 46, 2]\), so the magic fingerprint of \(5913\) is \(2\).
A number is considered lucky if its magic fingerprint is \(7\). Given two integers \(A\) and \(B\), your task is to count how many numbers in the interval \([A, B]\) are lucky.
inputFormat
The input consists of a single line containing two space-separated integers \(A\) and \(B\) (with \(A \le B\)), representing the range \([A, B]\) within which to count the lucky numbers.
outputFormat
Output a single integer: the number of lucky numbers in the interval \([A, B]\) (i.e., the numbers whose magic fingerprint is \(7\)).
sample
1 10
1