For any positive, base-10 integer N, define f(N) as the number of times you have to add up its digits until you get a one-digit number. For example, f(51) = 1 because 5+1 = 6, a one-digit number. Meanwhile, f(98) = 2, since 8+9 = 17, a two-digit number, and then adding up those digits gives you 1+7 = 8, a one-digit number.
Find the smallest whole number N such that f(N) = 4
Let {a,b,c,d,e} be the smallest value of N s.t. f(N) = {1,2,3,4,5}
d is the requested value
Clearly a=1, and you can easily verify that b=19.
c is the smallest N s.t. f(N)=3 or sod(N)=19.
Since 19/9 = 2 + 1/9, c=199 since it is the smallest number for which sod()=19. Two 9s and one 1, in order from smallest to largest.
Now find d, s.t. sod(d)=199.
Since 199/9 = 22 + 1/9,d must be a 1 followed by 22 9s:
d = 19999999999999999999999 which is the requested answer.
And e, the smallest N s.t. f(N)=5 is a 1 followed by 2222222222222222222222 9s.
--------
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
def sodCount(n):
""" Input an integer. Returns the number of times you have to appy the sod function to get to a single digit """
count = 0
m = n
while len(str(m)) > 1:
count += 1
m = sod(m)
return count
print(sodCount(19999999999999999999999))
Output: 4
|
Posted by Larry
on 2025-03-06 13:22:20 |