N is the smallest positive integer such that the sum of the digits of N is 18 and the sum of the digits of 2N is 27. Find N.
N: 1449 1+4+4+9 = 18
2N: 2898 2+8+9+8 = 27
--------------
def sod(n):
""" Input an integer. Returns the Sum of the Digits """
aList = list(str(n))
ans = 0
for c in aList:
ans = ans + int(c)
return ans
for n in range(10000):
if sod(n) == 18 and sod(2*n) == 27:
print(' N:',n, '\n', '2N:', 2*n)
break
|
Posted by Larry
on 2024-01-16 08:21:56 |