![]() |
VOOZH | about |
Given a series 2, 12, 36, 80, 150.. Find the n-th term of the series.
Examples :
Input : 2 Output : 12 Input : 4 Output : 80
If we take a closer look, we can notice that series is sum of squares and cubes of natural numbers (1, 4, 9, 16, 25, .....) + (1, 8, 27, 64, 125, ....).
Therefore n-th number of the series is n^2 + n^3
Output :
80
Time complexity: O(1) as only single step is required to calculate nth term from given formula
Auxiliary Space: O(1)