Program to check if N is a Enneadecagonal Number
Given a number N, the task is to check if N is an Enneadecagonal Number or not. If the number N is an Enneadecagonal Number then print “Yes” else print “No”.
Enneadecagonal Number is a 19-sided polygon in mathematics. It belongs to a class of figurative number. The number contains the number of dots and the dots are arranged in a pattern or series. An Enneadecagonal Number is also known as Nonadecagon. The dots have common points and all other dots are arrange in the successive layer. The nth Enneadecagonal Number counts the seventeen number of dots and all the other dots are surrounding with a common sharing corner and make a pattern. The first few Enneadecagonal Numbers are 1, 19, 54, 106, 175…
Input: N = 19
Second Enneadecagonal Number is 19.
Input: N = 30
1. The Kth term of the Enneadecagonal Number is given as
2. As we have to check whether the given number can be expressed as an Enneadecagonal Number or not. This can be checked as:
3. If the value of K calculated using the above formula is an integer, then N is an Enneadecagonal Number.
4. Else N is not an Enneadecagonal Number.
Below is the implementation of the above approach:
Time Complexity: O(log N) because sqrt() function is being used
Auxiliary Space: O(1)