VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-nth-term-of-0-9-24-45/

⇱ Find nth term of 0, 9, 24, 45, . . . . - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find nth term of 0, 9, 24, 45, . . . .

Last Updated : 1 Feb, 2022

Given a natural number N, the task is to find the Nth term of the series 

0, 9, 24, 45, . . . .till N terms

Examples:

Input: N = 4 
Output: 45

Input: N = 6
Output: 105

Approach:

From the given series, find the formula for Nth term-

1st term = 3 * 1 * 1 - 3 = 0 

2nd term = 3 * 2 * 2 - 3 = 9 

3rd term = 3 * 3 * 3 - 3 = 24

4th term = 3 * 4 * 4 - 3 = 45

.

.

Nth term = 3 * N * N - 3

The Nth term of the given series can be generalized as-

TN = 3 * N * N - 3

Illustration:

Input: N = 6
Output: 105
Explanation:
TN = 3 * N * N - 3
     = 3 * 6 * 6 - 3
     = 108 - 3
     = 105

Below is the implementation of the above approach-


Output
105

Time Complexity: O(1)

Auxiliary Space: O(1) 

Comment