*Author:* Aryan KD

*Tester:* Aryan KD

*Editorialist:* Aryan KD

# DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

# PREREQUISITES:

Math .

# PROBLEM:

Noob is very intelligent in his class , he always play many mind games there for he has sharp mind but now his teacher is given a challenge to him he is given a series and he has to find Nth term in the series.

0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12 . . .

# EXPLANATION:

We have to find Nth term in given sequence here if we observe then there is in odd index all the number is addition by 2 in previous number and in even place all the number is addition of 1 in previous number so we have to iterate our loop according to given condition and find out our term

suppose N = 5

here N is 5 that is odd number there for we have to find addition of 2 in two times hence the output is 4

# SOLUTIONS:

## Setter's Solution

#include<bits/stdc++.h>

using namespace std;

void testcase()

{ //0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12 . . .

long long int n,k=0,sum=0;

cin>>n;

if(n<3){

cout<<“0”;

}

else if(n%2!=0){

n=n/2+1;

k=(n-1)*2;

cout<<k;

}

else{

n=n/2;

sum=(n-1);

cout<<sum;

}

}

int main()

{

int t;

cin>>t;

while(t–)

{

testcase();

cout<<endl;

}

return 0;

}

## Tester's Solution

#include<bits/stdc++.h>

using namespace std;

void testcase()

{ //0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12 . . .

long long int n,k=0,sum=0;

cin>>n;

if(n<3){

cout<<“0”;

}

else if(n%2!=0){

n=n/2+1;

k=(n-1)*2;

cout<<k;

}

else{

n=n/2;

sum=(n-1);

cout<<sum;

}

}

int main()

{

int t;

cin>>t;

while(t–)

{

testcase();

cout<<endl;

}

return 0;

}

## Editorialist's Solution

#include<bits/stdc++.h>

using namespace std;

void testcase()

{ //0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12 . . .

long long int n,k=0,sum=0;

cin>>n;

if(n<3){

cout<<“0”;

}

else if(n%2!=0){

n=n/2+1;

k=(n-1)*2;

cout<<k;

}

else{

n=n/2;

sum=(n-1);

cout<<sum;

}

}

int main()

{

int t;

cin>>t;

while(t–)

{

testcase();

cout<<endl;

}

return 0;

}