Given a number N. The task is to write a program to find the Nth term in the below series:
0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8,…..
Examples:
Input : N = 10 Output : 4 Input : N = 7 Output : 6
On observing carefully, you will find that the series is a mixture of 2 series:
 Terms at odd positions in the given series form the series of even numbers in increasing order starting from 0. Like, 0,2,4,6,..
 Terms at even positions in the given series are derived from the previous term using the formula (previousTerm/2). That is, the terms at even positions are half of their previous term.
Now, it is known that every odd positioned term forms an even series starting from 0 and every even positioned term is the half of the previous odd positioned term.
Therefore first check whether the input number N is even or odd. If it is odd, set N=(N/2) + 1(since there are Two series running parallelly) and find the Nth term by using formula 2*(N1) ( N1 because the series starts with 0).
Similarly, if N is even, set N = N/2, use the previous formula and divide the answer by 2.
Below is the implementation of above approach:
// CPP program to find Nth term // in the series #include <iostream> #include <math.h> using namespace std;
// Function to find Nth term // in the series void findNthTerm( int n)
{ // If n is even
if (n % 2 == 0) {
n = n / 2;
n = 2 * (n  1);
cout << n / 2 << endl;
}
// If n is odd
else {
n = (n / 2) + 1;
n = 2 * (n  1);
cout << n << endl;
}
} // Driver code int main()
{ int X = 10;
findNthTerm(X);
X = 7;
findNthTerm(X);
return 0;
} 
// Java program to find Nth term // in the series // Function to find Nth term // in the series class GFG
{ static void findNthTerm( int n)
{ // If n is even
if (n % 2 == 0 )
{
n = n / 2 ;
n = 2 * (n  1 );
System.out.println(n / 2 );
}
// If n is odd
else {
n = (n / 2 ) + 1 ;
n = 2 * (n  1 );
System.out.println(n);
}
} // Driver code public static void main(String args[])
{ int X = 10 ;
findNthTerm(X);
X = 7 ;
findNthTerm(X);
} } // This code is contributed by Subhadeep 
# Python 3 program to find Nth term # in the series # Function to find Nth term # in the series def findNthTerm(n):
# If n is even
if (n % 2 = = 0 ):
n = n / / 2
n = 2 * (n  1 )
print ( n / / 2 )
# If n is odd
else :
n = (n / / 2 ) + 1
n = 2 * (n  1 )
print (n)
# Driver code if __name__ = = "__main__" :
X = 10
findNthTerm(X);
X = 7 ;
findNthTerm(X)

// C# program to find Nth term // in the series using System;
// Function to find Nth term // in the series class GFG
{ static void findNthTerm( int n)
{ // If n is even
if (n % 2 == 0)
{
n = n / 2;
n = 2 * (n  1);
Console.Write(n / 2);
}
// If n is odd
else
{
n = (n / 2) + 1;
n = 2 * (n  1);
Console.Write(n);
}
} // Driver code public static void Main()
{ int X = 10;
findNthTerm(X);
Console.Write( "\n" );
X = 7;
findNthTerm(X);
} } // This code is contributed // by Smitha 
<?php // PHP program to find Nth // term in the series // Function to find Nth // term in the series function findNthTerm( $n )
{ // If $n is even
if ( $n % 2 == 0)
{
$n = $n / 2;
$n = 2 * ( $n  1);
echo $n / 2 . "\n" ;
}
// If $n is odd
else {
$n = (int)( $n / 2) + 1;
$n = 2 * ( $n  1);
echo $n . "\n" ;
}
} // Driver code $X = 10;
findNthTerm( $X );
$X = 7;
findNthTerm( $X );
// This code is contributed // by ChitraNayal ?> 
4 6
Recommended Posts:
 Find Nth term of the series where each term differs by 6 and 2 alternately
 Program to find Nth term in the given Series
 Program to find the Nth term of the series 3, 7, 13, 21, 31.....
 Program to find Nth term of series 1, 3, 12, 60, 360…
 Program to find the Nth term of series 1, 2, 11, 26, 47......
 Program to find Nth term of series 9, 23, 45, 75, 113...
 Program to find Nth term in the series 0, 2, 1, 3, 1, 5, 2, 7, 3,…
 Program to find the Nth term of the series 3, 20, 63, 144, 230, ……
 Program to find the Nth term of series 5, 10, 17, 26, 37, 50, 65, 82, ...
 Program to find the Nth term of series 0, 4, 14, 30, 51, 80, 114, 154, 200, ...
 Program to find the Nth term of the series 0, 14, 40, 78, 124, ...
 Program to find the Nth term of the series 0, 5, 14, 27, 44, ........
 Program to find Nth term of the series 3, 6, 18, 24, ...
 Program to find Nth term of the series 2, 4, 3, 4, 15...
 Program to find Nth term of the series 3, 12, 29, 54, 87, ...
 Program to find Nth term of the series 3 , 5 , 21 , 51 , 95 , ...
 Program to find the Nth term of the series 0, 5, 18, 39, 67, 105, 150, 203, ...
 Program to find Nth term of series 0, 7, 18, 33, 51, 75, 102, 133, .....
 Program to find Nth term of series 0, 10, 30, 60, 99, 150, 210, 280...........
 Program to find Nth term of series 2, 12, 28, 50, 77, 112, 152, 198, .....
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.