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
function findSum ( a , b , n ) { var sum = 0 ; var x = a ^ b ; if ( n % 3 == 0 ) { sum = parseInt ( n / 3 ) * ( a + b + x ) ; } else if ( n % 3 == 1 ) { sum = parseInt ( n / 3 ) * ( a + b + x ) + a ; } else { sum = parseInt ( n / 3 ) * ( a + b + x ) + a + b ; } document . write ( sum ) ; } var a = 2 , b = 5 , N = 8 ; findSum ( a , b , N ) ;