+ 1

Help me with miniprogram (python)

F(n) = G(n - 2), ŠµŃŠ»Šø n > 2 G(n) = F(n - 1) + n, ŠµŃŠ»Šø n > 1

17th Jan 2021, 6:01 PM
VVaryag
VVaryag - avatar
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
20th Jan 2021, 1:03 PM
Mohammad Reza Sharifi Khorasani
Mohammad Reza Sharifi Khorasani - avatar