Given an integer **N**, the task is to check if it is a Centered heptagonal number or not.

Centered heptagonal numberis 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, …

**Examples:**

Input:N = 8

Output:Yes

Explanation:

8 is the Second Centered heptagonal number.

Input:20

Output:No

Explanation:

20 is not a Centered heptagonal number.

**Approach:**

To solve the problem mentioned above we have to know that the K^{th} 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:

## C++

`// C++ implementation to check that ` `// a number is a Centered ` `// heptagonal number or not ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to check that the ` `// number is a Centered ` `// heptagonal number ` `bool` `isCenteredheptagonal(` `int` `N) ` `{ ` ` ` `float` `n = (7 + ` `sqrt` `(56 * N - 7)) / 14; ` ` ` ` ` `// Condition to check if the ` ` ` `// number is a Centered heptagonal number ` ` ` `return` `(n - (` `int` `)n) == 0; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `n = 8; ` ` ` ` ` `// Function call ` ` ` `if` `(isCenteredheptagonal(n)) { ` ` ` `cout << ` `"Yes"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"No"` `; ` ` ` `} ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation to check that ` `// a number is a Centered ` `// heptagonal number or not ` `import` `java.lang.Math; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to check that the ` `// number is a Centered ` `// heptagonal number ` `public` `static` `boolean` `isCenteredheptagonal(` `int` `N) ` `{ ` ` ` `double` `n = (` `7` `+ Math.sqrt(` `56` `* N - ` `7` `)) / ` `14` `; ` ` ` ` ` `// Condition to check if the ` ` ` `// number is a Centered heptagonal number ` ` ` `return` `(n - (` `int` `)n) == ` `0` `; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `8` `; ` ` ` ` ` `// Function call ` ` ` `if` `(isCenteredheptagonal(n)) ` ` ` `{ ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` `} ` `} ` ` ` `// This code is contributed by divyeshrabadiya07 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation to check ` `# that a number is a centered ` `# heptagonal number or not ` `import` `math ` ` ` `# Function to check that the ` `# number is a centered ` `# heptagonal number ` `def` `isCenteredheptagonal(N): ` ` ` ` ` `n ` `=` `(` `7` `+` `math.sqrt(` `56` `*` `N ` `-` `7` `)) ` `/` `14` ` ` ` ` `# Condition to check if the number ` ` ` `# is a centered heptagonal number ` ` ` `return` `(n ` `-` `int` `(n)) ` `=` `=` `0` ` ` `# Driver Code ` `n ` `=` `8` ` ` `# Function call ` `if` `(isCenteredheptagonal(n)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed by ShubhamCoder ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation to check that ` `// a number is a centered ` `// heptagonal number or not ` `using` `System; ` ` ` `class` `GFG{ ` ` ` `// Function to check that the ` `// number is a centered ` `// heptagonal number ` `static` `bool` `isCenteredheptagonal(` `int` `N) ` `{ ` ` ` `double` `n = (7 + Math.Sqrt(56 * N - 7)) / 14; ` ` ` ` ` `// Condition to check if the number ` ` ` `// is a centered heptagonal number ` ` ` `return` `(n - (` `int` `)n) == 0; ` `} ` ` ` `// Driver Code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `n = 8; ` ` ` ` ` `// Function call ` ` ` `if` `(isCenteredheptagonal(n)) ` ` ` `{ ` ` ` `Console.Write(` `"Yes"` `); ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `Console.Write(` `"No"` `); ` ` ` `} ` `} ` `} ` ` ` `// This code is contributed by ShubhamCoder ` |

*chevron_right*

*filter_none*

**Output:**

Yes

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.

## Recommended Posts:

- Centered heptagonal number
- Find the sum of the first N Centered heptagonal number
- Program to check if N is a Heptagonal Number
- Heptagonal number
- Second heptagonal numbers
- Program to check if N is a Centered nonadecagonal number
- Program to check if N is a Centered Hexagonal Number
- Program to check if N is a Centered Octadecagonal number
- Program to check if N is a Centered Octagonal Number
- Program to check if N is a Centered Decagonal Number
- Program to check if N is a Centered Tridecagonal Number
- Program to check if N is a Centered dodecagonal number
- Program to check if N is a Centered Pentadecagonal Number
- Program to check if N is a Centered Hexadecagonal Number
- Program to check if N is a Centered Pentagonal Number or not
- Program to check if N is a Centered Triangular Number
- Program to check if N is a Centered Cubic Number
- Program for centered nonagonal number
- Program for Centered Icosahedral Number
- Centered cube number

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.