Given an integer N print the sequence number of the given Triangular Number. If the number is not a triangular number then print -1.
A number is termed as a triangular number if we can represent it in the form of a triangular grid of points such that the points form an equilateral triangle and each row contains as many points as the row number, i.e., the first row has one point, the second row has two points, the third row has three points and so on.
First 10 tringular number are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55.
Input: N = 21
Since 15 is a 6th Tringular Number.
Input: N = 12
Since 12 is not a tringular Number
- Since tringular numbers are sum of natural numbers so can be generalise as quadratic equation.
Time Complexity: O(1)
Auxiliary Space: O(1)