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.
def calculateSumDigits(number):
s = 0
for d in str(number):
s += int(d)
return s
def calculateDivisor(number):
for i in range(number+1, number*1000000):
if i%number == 0 and calculateSumDigits(i)==number:
return i
return -1
number = int(input("Enter a number: "))
print(calculateDivisor(number))
Comments
Leave a comment