Given an integer N, the task is to check if it is a Centered nonadecagonal number or not.
Centered nonadecagonal number represents a dot in the centre and other dots surrounding it in successive nonadecagon(19 sided polygon) layers.The first few Centered nonadecagonal numbers are 1, 20, 58, 115, 191, 286
Input: N = 20
20 is the Second Centered nonadecagonal number is 20.
38 is not a Centered nonadecagonal number.
Approach: To solve the problem mentioned above we have to know that the Kth term of the Centered nonadecagonal number is given as:
As we have to check that the given number can be expressed as a Centered nonadecagonal number or not. This can be checked by generalizing the formula to:
Finally, check the value of computation using this formula if it is an integer, if yes then it means that N is a Centered nonadecagonal 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