banner



1 3 7 13 21

Plan to find the Nth term of the series 3, vii, 13, 21, 31…..

View Word

Improve Commodity

Relieve Article

Like Article

  • Read
  • Discuss
  • View Word

    Improve Article

    Save Article

    Similar Article

    Given a number Due north, the task is to notice the Nth term of this serial:

    3, seven, thirteen, 21, 31, …….

    Examples:

                Input:            N = iv            Output:            21            Explanation:            Nth term = (pow(N, 2) + N + i)          = (pow(4, 2) + 4 + 1)          = 21            Input:            Northward = 11            Output:            133

    Approach:
    Sum = 0+3+7+13+21+31+........+a_{n-1} + a_n\\ Sum = 3+7+13+21+31+...+a_{n-2}+a_{n-1}+a_n
    Subtracting these two equations we get
     0=3+\left \{\frac{n-1}{2}\right \}[2*4 + (n-2)*2]-a_n\\ =3+\left \{\frac{n-1}{2}\right \}[8 + 2n-4]-a_n\\ =3+\left \{\frac{n-1}{2}\right \}[2n+4]-a_n\\ a_n=3+(n-1)(n+2)\\ a_n=n^2+n+1
    Therefore, the Nth Term of the given series is:

                a_n=n^2+n+1          

    Below is the implementation of the to a higher place approach:

    C++

    #include <iostream>

    #include <math.h>

    using namespace std;

    long long int getNthTerm( long long int North)

    {

    return ( pow (N, 2) + N + 1);

    }

    int main()

    {

    long long int N = 11;

    cout << getNthTerm(North);

    return 0;

    }

    Java

    import java.util.*;

    class solution

    {

    static long getNthTerm( long N)

    {

    return (( int )Math.pow(N, two ) + N + 1 );

    }

    public static void primary(String arr[])

    {

    long North = 11 ;

    System.out.println(getNthTerm(N));

    }

    }

    Python3

    def getNthTerm(N):

    return ( pw (N, 2 ) + N + i )

    if __name__ = = '__main__' :

    Due north = eleven

    print (getNthTerm(N))

    C#

    using System;

    class GFG

    {

    static long getNthTerm( long N)

    {

    return (( int )Math.Pow(N, ii) + N + 1);

    }

    static public void Main ()

    {

    long N = 11;

    Console.Write(getNthTerm(North));

    }

    }

    PHP

    <?php

    function getNthTerm( $N )

    {

    render (pow( $Northward , 2) + $Due north + 1);

    }

    $Due north = eleven;

    echo getNthTerm( $North );

    ?>

    Javascript

    <script>

    function getNthTerm(North)

    {

    return (Math.pow(North, two) + Due north + 1);

    }

    let N = 11;

    document.write(getNthTerm(N));

    </script>

    Time Complexity: O(1)

    Space Complexity: O(1) since using constant variables


    1 3 7 13 21,

    Source: https://www.geeksforgeeks.org/program-to-find-the-nth-term-of-the-series-3-7-13-21-31/

    Posted by: shawpuble1956.blogspot.com

    0 Response to "1 3 7 13 21"

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel