Given an integer N, the task is to check if it is a Centered Octadecagonal number or not. Print “yes” if it is otherwise output is “no”.
Centered Octadecagonal number represents a dot in the centre and others dot are arranged around it in successive layers of octadecagon(18 sided polygon). The first few Centered Octadecagonal numbers are 1, 19, 55, 109, 181, 271, 379, …
Input: N = 19
19 is the Second Centered Octadecagonal number is 19.
38 is not a Centered Octadecagonal number.
Approach: To solve the problem mentioned above we know that the Kth term of the Centered Octadecagonal number is given as:
As we have to check that the given number can be expressed as a Centered Octadecagonal number or not. This can be checked by generalizing the equation as:
Finally, check the value of computation using this formula if it is an integer, then it means that N is a Centered Octadecagonal number.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live