Centered Pentadecagonal Number

Given a number n, find the nth Centered Pentadecagonal Number .

A Centered Pentadecagonal Number represents a dot in the centre and other dots surrounding it in successive pentadecagonal(15-sided polygon) layers.

centered pentadecagonal number



Examples :

Input :  2
Output : 16

Input : 8
Output : 421

n-th term of Centered pentadecagonal number:-

 PD_{n}= (15n^2 -15n+2)/2

Below is the basic implementation of the above idea.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ Program to find 
// nth centered 
// pentadecagonal  number
#include <bits/stdc++.h>
using namespace std;
  
// centered pentadecagonal function
int center_pentadecagonal_num(long int n)
{
    // Formula to calculate nth
    // centered pentadecagonal number
    return (15 * n * n - 15 * n + 2) / 2;
}
  
// Driver Code
int main()
{
    long int n = 3;
    cout << n << "th number : " 
             << center_pentadecagonal_num(n);
    cout << endl;
    n = 10;
    cout << n << "th number : "
             << center_pentadecagonal_num(n);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program to find nth centered 
// pentadecagonal number
  
import java.io.*;
  
class GFG {
      
    // centered pentadecagonal function
    static long center_pentadecagonal_num(long n)
    {
      
        // Formula to calculate nth
        // centered pentadecagonal number
        return (15 * n * n - 15 * n + 2) / 2;
    }
      
    // Driver Code
    public static void main (String[] args) 
    {
      
        long n = 3;
        System.out.print(n + "th number : ");
        System.out.println( 
                  center_pentadecagonal_num(n));
          
        n = 10;
        System.out.print( n + "th number : ");
        System.out.println(
                 center_pentadecagonal_num(n));
    }
}
  
// This code is contributed by ajit.

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Program to find nth
#centered pentadecagonal number
  
def center_pentadecagonal_num(n) :
      
    # Formula to calculate nth
    # centered pentadecagonal number
    return (15 * n * n - 15 * n + 2) // 2
  
# Driver Code
if __name__ == '__main__' :
          
    n = 3
    print(n,"rd number : ",
                center_pentadecagonal_num(n))
    n = 10
    print(n,"th number : ",
                 center_pentadecagonal_num(n))
                   
  
# This code is contributed  by m_kit

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Program to find 
// nth centered 
// pentadecagonal number
using System;
  
class GFG
{
      
    // centered 
    // pentadecagonal function
    static long center_pentadecagonal_num(long n)
    {
      
        // Formula to calculate 
        // nth centered 
        // pentadecagonal number
        return (15 * n * n -
                15 * n + 2) / 2;
    }
      
    // Driver Code
    static public void Main ()
    {
        long n = 3;
        Console.Write(n + "th number : ");
        Console.WriteLine( 
                center_pentadecagonal_num(n));
          
        n = 10;
        Console.Write( n + "th number : ");
        Console.WriteLine(
                center_pentadecagonal_num(n));
    }
}
  
// This code is contributed by ajit.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP Program to find 
// nth centered 
// pentadecagonal number
  
// centered pentadecagonal function
function center_pentadecagonal_num($n)
{
    // Formula to calculate nth
    // centered pentadecagonal number
    return (15 * $n * $n -
            15 * $n + 2) / 2;
}
  
// Driver Code
$n = 3;
echo $n , "th number : ",
        center_pentadecagonal_num($n);
echo "\n";
$n = 10;
echo $n , "th number : ",
        center_pentadecagonal_num($n);
  
// This code is contributed by m_kit
?>

chevron_right



Output :

3th number : 46
10th number : 676


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : jit_t