Program to check if N is a Tridecagonal Number or not
Given an integer N, the task is to check if it is a Tridecagonal number or not.
Tridecagon number is a thirteen-sided polygon. The first few Tridecagon numbers are 1, 13, 36, 70, 115, 171, …
Input: N = 13
Second Tridecagon number is 13.
Input: N = 30
- The Kth term of the Tridecagon number is given as
- As we have to check that the given number can be expressed as a Tridecagon number or not. This can be checked as follows –
- Finally, check the value of computed using this formulae is an integer, which means that N is a Tridecagon number.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
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.