#P1822. 魔法指纹

魔法指纹

Description

For any positive integer nn with at least two digits, define magic(n)\mathrm{magic}(n) as follows: write down the digits of nn in decimal order, and for each adjacent pair of digits, write the absolute value of their difference. This yields a new number; remove any leading zeros, and define the result as magic(n)\mathrm{magic}(n). In particular, if nn is a single-digit number, then magic(n)=n\mathrm{magic}(n)=n.

For example: magic(5913)=482\mathrm{magic}(5913)=482, magic(1198)=081=81\mathrm{magic}(1198)=081=81, magic(666)=00=0\mathrm{magic}(666)=00=0.

For any number nn, repeatedly apply magic\mathrm{magic} until nn becomes a single-digit number; this produces a sequence $[n,\mathrm{magic}(n),\mathrm{magic}(\mathrm{magic}(n)),\cdots]$. The final value is called the magic\mathrm{magic} fingerprint of nn.

For example, for n=5913n=5913, we get the sequence [5913,482,46,2][5913,482,46,2]. Thus, the magic\mathrm{magic} fingerprint of 59135913 is 22.

If a number’s magic\mathrm{magic} fingerprint is 77, we consider it a lucky number.

Now, given A,BA, B, compute how many numbers in [A,B][A,B] are lucky numbers.

Input Format

The input consists of two lines, one number per line. The first line is AA, and the second line is BB.

Output Format

Output how many numbers in [A,B][A,B] are lucky numbers.

1
9
1

Hint

Constraints and Conventions

  • For 30%30\% of the testdata, B104B \le 10^4.
  • For 100%100\% of the testdata, 0<AB1090 < A \le B \le 10^9.

Translated by ChatGPT 5