# Program to check if N is a Centered Pentadecagonal Number

• Last Updated : 09 Apr, 2021

Given a number N, the task is to check whether N is a Centered pentadecagonal number or not. If the number N is a Centered Pentadecagonal Number then print “Yes” else print “No”.

Centered Pentadecagonal Number represents a dot in the centre and other dots surrounding it in successive Pentadecagonal(15-sided polygon) layers. The first few Centered pentadecagonal numbers are 1, 16, 46 …

Examples:

Input: N = 16
Output: Yes
Explanation:
Second Centered pentadecagonal number is 16.

Input: N = 20
Output: No

Approach:

1. The Kth term of the Centered pentadecagonal number is given as:

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

=>
=>

3. If the value of K calculated using the above formula is an integer, then N is a Centered Pentadecagonal Number.

4. Else the number N is not a Centered Pentadecagonal 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 Pentadecagonal Numberbool isCenteredpentadecagonal(int N){    float n        = (16 + sqrt(120 * N + 105))          / 30;     // Condition to check if N is a    // Centered Pentadecagonal Number    return (n - (int)n) == 0;} // Driver Codeint main(){    // Given Number    int N = 16;     // Function call    if (isCenteredpentadecagonal(N)) {        cout << "Yes";    }    else {        cout << "No";    }    return 0;}

## Java

 // Java program for the above approachclass GFG{ // Function to check if number N is a// Centered Pentadecagonal Numberstatic boolean isCenteredpentadecagonal(int N){    float n = (float)(16 + Math.sqrt(120 * N +                                     105)) / 30;     // Condition to check if N is a    // Centered Pentadecagonal Number    return (n - (int)n) == 0;} // Driver Codepublic static void main(String[] args){    // Given Number    int N = 16;     // Function call    if (isCenteredpentadecagonal(N))    {        System.out.println("Yes");    }    else    {        System.out.println("No");    }}} // This code is contributed by rutvik_56

## Python3

 # Python3 program for the above approachimport math # Function to check if number N is a# centered pentadecagonal numberdef isCenteredpentadecagonal(N):         n = (16 + math.sqrt(120 * N + 105)) / 30         # Condition to check if N is a    # centered pentadecagonal number    return (n - int(n)) == 0 # Driver CodeN = 16 # Function callif isCenteredpentadecagonal(N):    print("Yes")else :    print("No") # This code is contributed by ishayadav181

## C#

 // C# program for the above approachusing System;class GFG{     // Function to check if number N is a// centered pentadecagonal numberpublic static bool isCenteredpentadecagonal(int N){    double n = (16 + Math.Sqrt(120 * N +                               105)) / 30;         // Condition to check if N is a    // centered pentadecagonal number    return (n - (int)n) == 0;} // Driver codepublic static void Main(){         // Given number    int N = 16;         // Function call    if (isCenteredpentadecagonal(N))    {        Console.WriteLine("Yes");    }    else    {        Console.WriteLine("No");    }}} // This code is contributed by divyeshrabadiya07

## Javascript

 

Output:

No

Time Complexity: O(1)

Auxiliary Space: O(1)

My Personal Notes arrow_drop_up