Given an integer num (1<n<100). Find a minimal divisor that is not equal to the given number and the sum is equal to the given number. Input: 9
Output: 18
# Function to get sum of digits
def getSumDigits(number):
sumResult = 0
for digit in str(number):
sumResult += int(digit)
return sumResult
def getMinimalDivisor(number):
for i in range(number+1, number*1000000):
if i%number == 0 and getSumDigits(i)==number:
return i
return -1
number = int(input("Enter a number: "))
minimalDivisor=getMinimalDivisor(number)
if minimalDivisor==-1:
print ("No minimal divisor for number {}".format(number))
else:
print ("The minimal divisor for number {} is {}".format(number,minimalDivisor ))
Comments
Leave a comment