Sum of the first N terms of XOR Fibonacci series | Function to calculate the sum of the first N terms of XOR Fibonacci Series ; Base case ; Stores the sum of the first N terms ; Iterate from [ 0 , n - 3 ] ; Store XOR of last 2 elements ; Update sum ; Update the first element ; Update the second element ; Print the final sum ; Driver code ; Function call
def findSum ( a , b , N ) : NEW_LINE INDENT if N == 1 : NEW_LINE INDENT print ( a ) NEW_LINE return NEW_LINE DEDENT s = a + b NEW_LINE for i in range ( 0 , N - 2 ) : NEW_LINE INDENT x = a ^ b NEW_LINE s += x NEW_LINE a = b NEW_LINE b = x NEW_LINE DEDENT print ( s ) NEW_LINE return NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 2 NEW_LINE b = 5 NEW_LINE N = 8 NEW_LINE findSum ( a , b , N ) NEW_LINE DEDENT