#P1822. 魔法指纹
魔法指纹
Description
For any positive integer with at least two digits, define as follows: write down the digits of 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 . In particular, if is a single-digit number, then .
For example: , , .
For any number , repeatedly apply until 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 fingerprint of .
For example, for , we get the sequence . Thus, the fingerprint of is .
If a number’s fingerprint is , we consider it a lucky number.
Now, given , compute how many numbers in are lucky numbers.
Input Format
The input consists of two lines, one number per line. The first line is , and the second line is .
Output Format
Output how many numbers in are lucky numbers.
1
9
1
Hint
Constraints and Conventions
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号