# Program to check if N is a Enneadecagonal Number

• Last Updated : 05 Dec, 2022

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

Enneadecagonal Number is a 19-sided polygon in mathematics. It belongs to a class of figurative number. The number contains the number of dots and the dots are arranged in a pattern or series. An Enneadecagonal Number is also known as Nonadecagon. The dots have common points and all other dots are arrange in the successive layer. The nth Enneadecagonal Number counts the seventeen number of dots and all the other dots are surrounding with a common sharing corner and make a pattern. The first few Enneadecagonal Numbers are 1, 19, 54, 106, 175…

Examples:

Input: N = 19
Output: Yes
Explanation:

Input: N = 30
Output: No

Approach:

1. The Kth term of the Enneadecagonal Number is given as

2. As we have to check whether the given number can be expressed as an Enneadecagonal 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 an Enneadecagonal Number.
4. Else N is not an Enneadecagonal 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 enneadecagonal numberbool isenneadecagonal(int N){    float n        = (15 + sqrt(136 * N + 225))          / 34;     // Condition to check if N is a    // enneadecagonal number    return (n - (int)n) == 0;} // Driver Codeint main(){    // Given Number    int N = 19;     // Function call    if (isenneadecagonal(N)) {        cout << "Yes";    }    else {        cout << "No";    }    return 0;}

## Java

 // Java program for the above approachclass GFG{ // Function to check if number N// is a enneadecagonal numberstatic boolean isenneadecagonal(int N){    float n = (float)(15 + Math.sqrt(136 * N +                                     225)) / 34;     // Condition to check if N is a    // enneadecagonal number    return (n - (int)n) == 0;} // Driver Codepublic static void main(String[] args){         // Given Number    int N = 19;     // Function call    if (isenneadecagonal(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 enneadecagonal numberdef isenneadecagonal(N):     n = (15 + math.sqrt(136 * N + 225)) / 34     # Condition to check if N is a    # enneadecagonal number    return (n - int(n)) == 0 # Driver CodeN = 19 # Function callif (isenneadecagonal(N)):    print("Yes")else:    print("No") # This code is contributed by divyamohan123

## C#

 // C# program for the above approachusing System; class GFG{ // Function to check if number N// is a enneadecagonal numberstatic bool isenneadecagonal(int N){    float n = (float)(15 + Math.Sqrt(136 * N +                                     225)) / 34;         // Condition to check if N is a    // enneadecagonal number    return (n - (int)n) == 0;}     // Driver Codestatic public void Main (){             // Given number    int N = 19;         // Function call    if (isenneadecagonal(N))    {        Console.Write("Yes");    }    else    {        Console.Write("No");    }}} // This code is contributed by shubhamsingh10

## Javascript

 

Output

Yes

Time Complexity: O(log N) because sqrt() function is being used
Auxiliary Space: O(1)

My Personal Notes arrow_drop_up