def get(x, y, lst, dct): if y < x: return dct[(x, y)] return lst[x] def count(num): lst = [0, 1, 2] dct = {(2, 1): 1} if 3 > num: return lst[num] for x in range(3, num + 1): tale = 0 for n in range(1, x): tale += get(x - n, n, lst, dct) dct[(x, n)] = tale lst.append(tale + 1) return lst[num] - 1 print(count(100))