n,k = 40,20 fibo = [1] for i in range(1,k): fibo.append(1+sum(fibo[:i])) for i in range(k+1,n+1): fibo.append(sum(fibo[i-k-1:i])) print(fibo[n-1])