Sum of the first N terms of XOR Fibonacci series | Function to calculate sum of the first N terms of XOR Fibonacci Series ; Store the sum of first n terms ; Store xor of a and b ; Case 1 : If n is divisible by 3 ; Case 2 : If n % 3 leaves remainder 1 ; Case 3 : If n % 3 leaves remainder 2 on division by 3 ; Print the final sum ; Driver code ; Function call
def findSum ( a , b , N ) : NEW_LINE INDENT sum = 0 NEW_LINE x = a ^ b NEW_LINE if N % 3 == 0 : NEW_LINE INDENT sum = ( N // 3 ) * ( a + b + x ) NEW_LINE DEDENT elif N % 3 == 1 : NEW_LINE INDENT sum = ( N // 3 ) * ( a + b + x ) + a NEW_LINE DEDENT else : NEW_LINE INDENT sum = ( N // 3 ) * ( a + b + x ) + a + b NEW_LINE DEDENT print ( sum ) 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