시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 192 MB 6498 3611 2978 56.231%

문제

어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이 된다. 따라서 245는 256의 생성자가 된다. 물론, 어떤 자연수의 경우에는 생성자가 없을 수도 있다. 반대로, 생성자가 여러 개인 자연수도 있을 수 있다.

자연수 N이 주어졌을 때, N의 가장 작은 생성자를 구해내는 프로그램을 작성하시오.

입력

첫째 줄에 자연수 N(1 ≤ N ≤ 1,000,000)이 주어진다.

출력

첫째 줄에 답을 출력한다. 생성자가 없는 경우에는 0을 출력한다.

예제 입력 1

216

예제 출력 1

198
W3sicHJvYmxlbV9pZCI6IjIyMzEiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJkODRcdWQ1NzRcdWQ1NjkiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzViNFx1YjVhNCBcdWM3OTBcdWM1ZjBcdWMyMTggTlx1Yzc3NCBcdWM3ODhcdWM3NDQgXHViNTRjLCBcdWFkZjggXHVjNzkwXHVjNWYwXHVjMjE4IE5cdWM3NTggXHViZDg0XHVkNTc0XHVkNTY5XHVjNzQwIE5cdWFjZmMgTlx1Yzc0NCBcdWM3NzRcdWI4ZThcdWIyOTQgXHVhYzAxIFx1Yzc5MFx1YjlhY1x1YzIxOFx1Yzc1OCBcdWQ1NjlcdWM3NDQgXHVjNzU4XHViYmY4XHVkNTVjXHViMmU0LiBcdWM1YjRcdWI1YTQgXHVjNzkwXHVjNWYwXHVjMjE4IE1cdWM3NTggXHViZDg0XHVkNTc0XHVkNTY5XHVjNzc0IE5cdWM3NzggXHVhY2JkXHVjNmIwLCBNXHVjNzQ0IE5cdWM3NTggXHVjMGRkXHVjMTMxXHVjNzkwXHViNzdjIFx1ZDU1Y1x1YjJlNC4gXHVj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