시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 9 2 2 40.000%

문제

양의 정수 n이 주어졌을 때, n의 배수 중에서 그 수를 구성하고 있는 서로 다른 숫자의 개수가 가장 작은 수 m을 구하는 프로그램을 작성하시오. 예를 들어 1334를 구성하는 서로 다른 숫자는 1, 3, 4 이다.

입력

입력은 여러 개의 테스트 케이스로 이루어져 있고, 각 테스트 케이스는 n이 포함되어 있는 한 줄로 이루어져 있다. 테스트 케이스는 50개를 넘지 않고, n은 65536보다 작거나 같은 자연수이다. 입력의 마지막 줄에는 0이 하나 주어진다.

출력

각 테스트 케이스에 대해서, 문제의 설명에 나와있는 m을 출력한다. 만약, 가능한 m이 여러가지인 경우에는 가장 작은 값을 출력한다.

예제 입력 1

7
15
16
101
0

예제 출력 1

7
555
16
1111
W3sicHJvYmxlbV9pZCI6Ijc3ODQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMxMWNcdWI4NWMgXHViMmU0XHViOTc4IFx1YzIyYlx1Yzc5MCIsImRlc2NyaXB0aW9uIjoiPHA+XHVjNTkxXHVjNzU4IFx1YzgxNVx1YzIxOCBuXHVjNzc0IFx1YzhmY1x1YzViNFx1Yzg0Y1x1Yzc0NCBcdWI1NGMsIG5cdWM3NTggXHViYzMwXHVjMjE4IFx1YzkxMVx1YzVkMFx1YzExYyBcdWFkZjggXHVjMjE4XHViOTdjIFx1YWQ2Y1x1YzEzMVx1ZDU1OFx1YWNlMCBcdWM3ODhcdWIyOTQgXHVjMTFjXHViODVjIFx1YjJlNFx1Yjk3OCBcdWMyMmJcdWM3OTBcdWM3NTggXHVhYzFjXHVjMjE4XHVhYzAwIFx1YWMwMFx1YzdhNSBcdWM3OTFcdWM3NDAgXHVjMjE4IG1cdWM3NDQgXHVhZDZjXHVkNTU4XHViMjk0IFx1ZDUwNFx1Yjg1Y1x1YWRmOFx1YjdhOFx1Yzc0NCBcdWM3OTFcdWMxMzFcdWQ1NThcdWMyZGN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