아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Runaround Numbers

면접 대비

시간 제한1초메모리 제한1024 MB

요약
정수 M이 주어질 때, M보다 큰 가장 작은 러너라운드 수를 찾는다. 러너라운드 수는 0이 아닌 서로 다른 숫자로 이루어지고, 순환 이동이 모든 자리를 한 번씩 방문한 뒤 시작점으로 돌아온다.
난이도

보통10점 중 5점

유형
수학, 시뮬레이션, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration:

  • If you start at the left digit (8 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'll end up at a new digit. Consider: 8 1 3 6 2 which requires cycling through eight digits: 1 3 6 2 8 1 3 6, thus the next digit is 6.
  • Repeat this "cycle" (this time for the six counts designated by the '6') and you should end on a new digit: 2 8 1 3 6 2, namely 2.
  • Repeat again (two digits this time): 8 1, yielding 1.
  • Continue again (one digit this time): 3, yielding 3.
  • One more time: 6 2 8 and you have ended up back where you started, after touching each digit once. If you don't end up back where you started after touching each digit once, your number is not a Runaround number.

Given a positive number M (that has anywhere from 1 through 10 digits), find and print the next runaround number higher than M, which will always fit into an unsigned long integer for the given test data.

입력

A single line with a single integer, M

출력

A single line containing the next runaround number higher than the input value, M.

예제1

  1. 예제 1

    입력
    81361
    
    예상 출력
    81362