Given an integer N, the task is to check if it is a Heptadecagonal Number or not. If the number N is an Heptadecagonal Number then print “Yes” else print “No”.
Heptadecagonal Number is class of figurate number. It has 17-sided polygon called heptadecagon. The N-th heptadecagonal number counts the seventeen number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few heptadecagonal numbers are 1, 17, 48, 94, 155, 231…
Input: N = 17
Second heptadecagonal number is 17.
Input: N = 30
1. The Kth term of the heptadecagonal number is given as
2. As we have to check that the given number can be expressed as a heptadecagonal number or not. This can be checked as follows –
3. If the value of K calculated using the above formula is an integer, then N is a Heptadecagonal Number.
4. Else N is not a Heptadecagonal 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.