Geek | Function to calculate the N - th Geek - onacci Number ; Stores the geekonacci series ; Store the first three terms of the series ; Iterate over the range [ 3 , N ] ; Update the value of arr [ i ] as the sum of previous 3 terms in the series ; Return the last element of arr [ ] as the N - th term ; Driver Code
def find ( A , B , C , N ) : NEW_LINE INDENT arr = [ 0 ] * N NEW_LINE arr [ 0 ] = A NEW_LINE arr [ 1 ] = B NEW_LINE arr [ 2 ] = C NEW_LINE for i in range ( 3 , N ) : NEW_LINE INDENT arr [ i ] = ( arr [ i - 1 ] + arr [ i - 2 ] + arr [ i - 3 ] ) NEW_LINE DEDENT return arr [ N - 1 ] NEW_LINE DEDENT A = 1 NEW_LINE B = 3 NEW_LINE C = 2 NEW_LINE N = 4 NEW_LINE print ( find ( A , B , C , N ) ) NEW_LINE