0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8 This series is a mixture of 2 series all the odd terms in this series form even numbers in ascending order and every even terms is derived from the previous  term using the formula (x/2)

Consider the below series :

0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8

  • This series is a mixture of 2 series all the odd terms in this series form even numbers in ascending order
  • Every even terms is derived from the previous  term using the formula (x/2)

Write a program to find the nth term in this series.

  1. The value n in a positive integer that should be read from STDIN the nth term that is calculated by the program should be written to STDOUT.
  2. Other than the value of the nth term no other characters /strings or message should be written to STDOUT.

For example

if n=10,the 10 th term in the series is to be derived from the 9th term in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be printed to STDOUT.

You can assume that the n will not exceed 20,000.

53 comments on “0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8 This series is a mixture of 2 series all the odd terms in this series form even numbers in ascending order and every even terms is derived from the previous  term using the formula (x/2)”


  • Arkaprava

    n=int(input())
    j=0
    x=[0]
    for i in range(n):
    x.append(i)
    j=j+2
    x.append(j)
    print(x)
    print(x[n-1])


  • Komirisetti

    #include
    int main ()
    {
    int n;
    scanf(“%d”,n);
    If(n%2!=2)
    printf (“%d”,(n/2)*2);
    else
    printf (“%d”,(n/2-1));
    return 0;
    }


  • ak025

    #include
    using namespace std;
    int main(){
    int n;
    cin>>n;
    int ans;

    if(n%2==0){
    int ans=(n/2)-1;
    cout<<ans;
    }
    else{
    ans=n-1;
    cout<<ans;
    }
    return 0;
    }


  • Madhukar

    #python code

    n = int(input(‘Enter the n value: ‘))
    i = 0

    for i in range(n):
    if i%2 == 0 :
    x = i
    else:
    x = int((i-1)/2)

    print(x)


  • Madhukar

    #Python code

    n = int(input(‘Enter the n value: ‘))
    i = 0

    for i in range(n):
    if i%2 == 0 :
    x = i
    else:
    x = int((i-1)/2)

    print(x)


  • Prasanta

    num=int(input(“Enter positive integer only: “))
    if num>20000:
    print(“Can’t get the Output BCZ num is greater than 20000.”)
    else:
    if num%2==0:
    print((num//2)-1)
    else:
    print(num-1)


  • Shinde

    Python code:
    num=int(input())

    if num%2!=0:
    print(num-1)
    else:
    if num==0:
    print(num)
    else:
    print((num-2)//2)


  • SUMIT

    #include

    using namespace std;

    int main()
    {
    int Nth;
    cin>>Nth;
    Nth = Nth-1;
    if((Nth)%2==0){
    cout<<Nth;
    }
    else{
    int k = (Nth-1)/2;
    cout<<k;
    }
    }


  • Subhankar

    #include
    void main()
    {
    int n, x;
    scanf(“%d”,&n);
    if(n%2!=0)
    x= 2*(n/2);
    else
    x = 1*(n-1)/2;
    printf(“%d”,x);
    }


  • parth

    #include
    using namespace std;
    int main(){
    int n;
    cin>>n;
    if(n%2==0)cout<<(n-1)/2;
    else cout<<n;
    }


  • parth

    #include
    using namespace std;
    int main(){
    int n;
    cin>>n;
    if(n%2==0)cout<<n;
    else cout<<(n-1)/2;
    }