14. For the given number ‘n’ (0 <n<= 100), little johnny wants to find out the minimum positive integer X divisible by ‘n’, where the sum of digits of X is equal to ‘n’ and X is not equal to 'n'.
Note: If such an 'X number does not exist, then the output should be - 1.
n = int(input("Enter n: "))
i = 1
flag = 0
while i < 10000000:
if i == n:
i = i + 1
continue
if i % n == 0:
x = [int(a) for a in str(i)]
b = sum(x)
if b == n:
print("Value is:", i)
flag = 1
break
i = i + 1
if flag == 0:
print(-1)
Comments
Leave a comment