시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 4300 2541 2105 57.577%

문제

어떤 자연수 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
W3sicHJvYmxlbV9pZCI6IjIyMzEiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJkODRcdWQ1NzRcdWQ1NjkiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzViNFx1YjVhNCBcdWM3OTBcdWM1ZjBcdWMyMTggTlx1Yzc3NCBcdWM3ODhcdWM3NDQgXHViNTRjLCBcdWFkZjggXHVjNzkwXHVjNWYwXHVjMjE4IE5cdWM3NTggXHViZDg0XHVkNTc0XHVkNTY5XHVjNzQwIE5cdWFjZmMgTlx1Yzc0NCBcdWM3NzRcdWI4ZThcdWIyOTQgXHVhYzAxIFx1Yzc5MFx1YjlhY1x1YzIxOFx1Yzc1OCBcdWQ1NjlcdWM3NDQgXHVjNzU4XHViYmY4XHVkNTVjXHViMmU0LiBcdWM1YjRcdWI1YTQgXHVjNzkwXHVjNWYwXHVjMjE4IE1cdWM3NTggXHViZDg0XHVkNTc0XHVkNTY5XHVjNzc0IE5cdWM3NzggXHVhY2JkXHVjNmIwLCBNXHVjNzQ0IE5cdWM3NTggXHVjMGRkXHVjMTMxXHVjNzkwXHViNzdjIFx1ZDU1Y1x1YjJlNC4gXHVjNjA4XH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