Answer to Question #256412 in Python for rasi

Question #256412

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.

  


1
Expert's answer
2021-10-27T07:41:01-0400
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS