Given a number n, find the n-th term in the series 1, 4, 27, 16, 125, 36, 343……..
Input : 5 Output : 125 Input : 6 Output : 36
Naive approach : In this Sequence, if the Nth term is even then the Nth term is square of N else Nth term is a cube of N.
N = 5
In this case, N is odd
N = N * N * N
N = 5 * 5 * 5
N = 125
N = 6
N = N * N
N = 6 * 6
N = 36 and so on..
Implementation of the above approach is given below:
Time Complexity : O(1)
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Program to find sum of elements in a given array
- Program to find largest element in an array
- Program to find GCD or HCF of two numbers
- Program to find LCM of two numbers
- Program to find transpose of a matrix
- Program to find area of a triangle
- Program to find area of a circle
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Find all angles of a given triangle
- Find count of digits in a number that divide the number
- Find a time for which angle between hour and minute hands is given theta
- Find other two sides of a right angle triangle
- Find start and ending index of an element in an unsorted array
- Find the missing number in a sorted array of limited range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.