from functools import cache def rule2str(number): num_str = str(number) length = len(num_str) middle = length // 2 left_part = num_str[:middle] right_part = num_str[middle:] return [str(int(left_part)), str(int(right_part))] values = {} def calc(start,end): if start == '0': result = calculateNumber('1',end) else: if len(start) % 2 == 0: x = rule2str(start) result = 0 result += calculateNumber(x[0],end) result += calculateNumber(x[1],end) else: result = calculateNumber(str(int(start)*2024),end) return result def calculateNumber(start,end): if end == 0: return 1 end -= 1 if (start,end) not in values: values[(start,end)] = calc(start,end) result = values[(start,end)] return result numbers = ['125','17'] # 2097446912 14168 4048 2 0 2 4 40 48 2024 40 48 80 96 2 8 6 7 6 0 3 2 result = 0 for i in numbers: result += calculateNumber(i,75) print(result)