Given an integer N, the task is to check if it is a Centered heptagonal number or not.
Centered heptagonal number is centered figure number that represents a heptagon with dot in center and all other dot surrounding in heptagonal form..The first few Centered heptagonal number are 1, 8, 22, 43, 71, 106, 148, …
Input: N = 8
8 is the Second Centered heptagonal number.
20 is not a Centered heptagonal number.
To solve the problem mentioned above we have to know that the Kth term of the Centered heptagonal number is given as:
As we have to check that the given number can be expressed as a Centered heptagonal 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, if yes then it means that N is a Centered heptagonal 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