Given a series 9, 33, 73, 129… Find the n-th term of the series.
Input : n = 4 Output : 129 Input : n = 5 Output : 201
The given series has a pattern which is visible after subtracting it from itself after one shift
S = 9 + 33 + 73 + 129 + … tn-1 + tn S = 9 + 33 + 73 + … tn-2 + tn-1 + tn ——————————————— 0 = 9 + (24 + 40 + 56 + ….) - tn Since 24 + 40 + 56.. series in A.P with common difference of 16, we get tn = 9 + [((n-1)/2)*(2*24 + (n-1-1)d)] On solving this we get tn = 8n2 + 1
Below is the implementation of the above approach:
Time complexity: O(1)
This article is contributed by Striver. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.