+ 1
Help me with miniprogram (python)
F(n) = G(n - 2), ŠµŃŠ»Šø n > 2 G(n) = F(n - 1) + n, ŠµŃŠ»Šø n > 1
1 Answer
0
I assume the initial values for F and G are equal to zero. Also calculate G(2) before for loop.
n = int(input())
F = [0, 0, 0]
G = [0, 0, 2]
for i in range(3, n + 1):
G.append(F[i-1] + i)
F.append(G[i-2])
The result for n = 7:
n = 0, 1, 2, 3, 4, 5, 6, 7
F = 0, 0, 0, 0, 2, 3, 4, 7
G = 0, 0, 2, 3, 4, 7, 9, 11