# Program to check if N is a Centered Decagonal Number

Last Updated : 19 Sep, 2022

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

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 numberbool 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 Codeint 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 Codepublic 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 approachimport numpy as np # Function to check if the number N# is a centered decagonal numberdef 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 Codestatic public void Main (){    int n = 11;          // Function call     if (isCentereddecagonal(n))     {         Console.Write("Yes");    }     else    {         Console.Write("No");    } }} // This code is contributed by ShubhamCoder

## Javascript

 

Output:
Yes

Time Complexity: O(logn)

Auxiliary Space: O(1)