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++
#include <bits/stdc++.h>
using namespace std;
bool isCentereddecagonal( int N)
{
float n
= (5 + sqrt (20 * N + 5))
/ 10;
return (n - ( int )n) == 0;
}
int main()
{
int N = 11;
if (isCentereddecagonal(N)) {
cout << "Yes" ;
}
else {
cout << "No" ;
}
return 0;
}
|
Java
import java.lang.Math;
class GFG{
public static boolean isCentereddecagonal( int N)
{
double n = ( 5 + Math.sqrt( 20 * N + 5 )) / 10 ;
return (n - ( int )n) == 0 ;
}
public static void main(String[] args)
{
int n = 11 ;
if (isCentereddecagonal(n))
{
System.out.println( "Yes" );
}
else
{
System.out.println( "No" );
}
}
}
|
Python3
import numpy as np
def isCentereddecagonal(N):
n = ( 5 + np.sqrt( 20 * N + 5 )) / 10
return (n - int (n)) = = 0
N = 11
if (isCentereddecagonal(N)):
print ( "Yes" )
else :
print ( "No" )
|
C#
using System;
class GFG{
static bool isCentereddecagonal( int N)
{
double n = (5 + Math.Sqrt(20 * N + 5)) / 10;
return (n - ( int )n) == 0;
}
static public void Main ()
{
int n = 11;
if (isCentereddecagonal(n))
{
Console.Write( "Yes" );
}
else
{
Console.Write( "No" );
}
}
}
|
Javascript
<script>
function isCentereddecagonal(N)
{
let n
= (5 + Math.sqrt(20 * N + 5))
/ 10;
return (n - parseInt(n)) == 0;
}
let N = 11;
if (isCentereddecagonal(N)) {
document.write( "Yes" );
}
else {
document.write( "No" );
}
</script>
|
Time Complexity: O(logn)
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!