# Program to check if N is a Centered Decagonal Number

Given an integer N, the task is to check if N is a Centered Decagonal Number or not. If the number N is a Centered Decagonal Number then print “Yes” else print “No”.

Centered Decagonal Number is centered figurative number that represents a decagon with dot in center and all other dot surrounding it in successive Decagonal Number form. The first few Centered decagonal numbers are 1, 11, 31, 61, 101, 151 …

Examples:

Input: N = 11
Output: Yes
Explanation:
Second Centered decagonal number is 11.

Input: N = 30
Output: No

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

1. The Kth term of the Centered Decagonal Number is given as

2. As we have to check that the given number can be expressed as a Centered Decagonal Number or not. This can be checked as follows:

=>
=>

3. If the value of K calculated using the above formula is an integer, then N is a Centered Decagonal Number.
4. Else the number N is not a Centered Decagonal Number.

Below is the implementation of the above approach:

## C++

 // C++ program for the above approach  #include  using namespace std;     // Function to check if number N  // is a Centered decagonal number  bool isCentereddecagonal(int N)  {      float n          = (5 + sqrt(20 * N + 5))            / 10;         // Condition to check if N      // is Centered Decagonal Number      return (n - (int)n) == 0;  }     // Driver Code  int main()  {      int N = 11;         // Function call      if (isCentereddecagonal(N)) {          cout << "Yes";      }      else {          cout << "No";      }      return 0;  }

## Java

 // Java implementation to check that a number  // is a centered decagonal number or not   import java.lang.Math;     class GFG{         // Function to check that the number   // is a centered decagonal number   public static boolean isCentereddecagonal(int N)   {       double n = (5 + Math.sqrt(20 * N + 5)) / 10;          // Condition to check if the number       // is a centered decagonal number       return (n - (int)n) == 0;   }      // Driver Code  public static void main(String[] args)   {      int n = 11;          // Function call       if (isCentereddecagonal(n))       {           System.out.println("Yes");      }       else     {           System.out.println("No");      }   }  }     // This code is contributed by ShubhamCoder

## Python3

 # Python3 program for the above approach  import numpy as np     # Function to check if the number N  # is a centered decagonal number  def isCentereddecagonal(N):         n = (5 + np.sqrt(20 * N + 5)) / 10        # Condition to check if N       # is centered decagonal number      return (n - int(n)) == 0    # Driver Code   N = 11    # Function call   if (isCentereddecagonal(N)):      print ("Yes")   else:      print ("No")     # This code is contributed by PratikBasu

## C#

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

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.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.