Skip to content
Related Articles
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)

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.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live

My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.6676941,"math_prob":0.95370156,"size":4029,"snap":"2021-21-2021-25","text_gpt3_token_len":1177,"char_repetition_ratio":0.20099379,"word_repetition_ratio":0.28789985,"special_character_ratio":0.29858527,"punctuation_ratio":0.105726875,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99074227,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,3,null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-13T00:41:41Z\",\"WARC-Record-ID\":\"<urn:uuid:456f437a-bba8-45c9-93b3-401b2de79b1c>\",\"Content-Length\":\"131075\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bf0837da-ff7d-450a-8d93-2a90988aa60a>\",\"WARC-Concurrent-To\":\"<urn:uuid:908e7b1b-4893-4e26-8320-91641669483a>\",\"WARC-IP-Address\":\"23.218.218.77\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/program-to-check-if-n-is-a-centered-pentadecagonal-number/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:Z2EL3QOAXBGGVPLMWGO2IPW5EBHAA6MY\",\"WARC-Block-Digest\":\"sha1:7QFWQ4EPFDUT3X6ADY2MVURHZHCS77VB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623487586465.3_warc_CC-MAIN-20210612222407-20210613012407-00364.warc.gz\"}"}