Find Me Out

Company: Nucleus Software

Difficulty: medium

Problem Statement

Find Me Out Problem Description Little Johnny picked a number N ( 0 < N <= 100 ) and wants to find the smallest positive integer X such that: X is divisible by N , the sum of the digits of X equals N , and X is not equal to N . If no such X exists, output -1 . Input Format A single line containing the integer N . Output Format Print a single integer: the smallest X satisfying all three conditions above, or -1 if no such X exists. Constraints 0 < N <= 100 X can be as large as 14 digits, which does not fit in a signed 32-bit integer -- use a 64-bit type ( long long in C++, long in Java; Python integers are unbounded). Examples Example 1: Input: 9 Output: 18 Explanation: 18 is divisible by 9 , the sum of its digits ( 1 + 8 ) is 9 , and 18 is not equal to 9 . No smaller positive integer satisfies all three conditions, so 18 is the answer. Example 2: Input: 10 Output: 190 Explanation: 190 is divisible by 10 , the sum of its digits ( 1 + 9 + 0 ) is 10 , and 190 is not equal to 10