#P1467. [USACO2.2] Runaround Numbers
[USACO2.2] Runaround Numbers
题目描述
Runaround numbers are integers with unique digits, none of which is zero (e.g., ) that also have an interesting property, exemplified by this demonstration:
-
If you start at the left digit ( in our number) and count that number of digits to the right, wrapping back to the first digit when no digits on the right are available, you will end up at a new digit. A number which does not end up at a new digit is not a runaround number. Consider: which cycles through eight digits: so the next digit is .
-
Repeat this cycle, this time for the six counts designed by the , and you should end on a new digit: , namely .
-
Repeat again, two digits this time: .
-
Continue again, one digit this time: .
-
One more time: and you have ended up back where you started after touching each digit once. If you do not end up back where you started after touching each digit once, your number is not a runaround number.
Given a number that has anywhere from through digits, find and print the next runaround number higher than . It will always fit into an unsigned long integer for the given test data.
输入格式
A single line with a single integer .
输出格式
A single line containing the next runaround number higher than the input value .
81361
81362
提示
USACO Training Section 2.2.