1. For a natural number n, define a function S(n) that returns the sum of each digit of n. 2.Define a function G(i) that finds all natural numbers m less than 10000 such that S(m) = i and returns them as an array. 3. 3. Find the natural number j such that len(G(j)) is maximal and output s = len(G(j)).
def S(n): sum = 0 while n: sum, n = sum + n % 10, n // 10 return sum def G(i): return [m for m in range(1, 10000) if S(m) == i] s = 0 for i in range(1, 100): g = G(i) if len(g) > s: s, j = len(g), i print(j)