📜  中心十二边形数

📅  最后修改于: 2021-04-29 08:53:09             🧑  作者: Mango

给定数字n,找到第n个中心十二边形数。
居中的十二边形数字表示连续十二边形(12面多边形)层中位于中心的点和围绕其的其他点。
例子 :

Input :  3
Output : 37

Input : 7
Output :253 

中心十二边形数

前几个居中的十二边形数字是:
1、13、37、73、121、181、253、337、433、541、661………………..
第n个居中十二边形数的公式:

CDg_{n}= 6n(n-1)+1

C++
// C++ Program to find
// nth centered
// Dodecagonal number
#include 
using namespace std;
 
// Function to calculate Centered
// Dodecagonal number
int centeredDodecagonal(long int n)
{
    // Formula to calculate nth
    // centered Dodecagonal number
    return 6 * n * (n - 1) + 1;
}
 
// Driver Code
int main()
{
    long int n = 2;
    cout << centeredDodecagonal(n);
    cout << endl;
    n = 9;
    cout << centeredDodecagonal(n);
 
    return 0;
}


Java
// Java Program to find nth
// centered dodecagonal number
import java.io.*;
 
class GFG{
     
// Function to calculate
// centered dodecagonal number
static long centeredDodecagonal(long n)
{
     
    // Formula to calculate nth
    // centered dodecagonal number
    return 6 * n * (n - 1) + 1;
}
 
// Driver Code
public static void main(String[] args)
{
    long n = 2;
    System.out.println(centeredDodecagonal(n));
 
    n = 9;
    System.out.println(centeredDodecagonal(n));
}
}
 
// This code is contributed by anuj_67


Python3
# Python3 program to find nth
# centered dodecagonal number
 
# Function to calculate
# centered dodecagonal number
def centeredDodecagonal(n) :
     
    # Formula to calculate nth
    # centered dodecagonal number
    return 6 * n * (n - 1) + 1;
 
# Driver code
n = 2
print(centeredDodecagonal(n));
 
n = 9
print(centeredDodecagonal(n));
 
# This code is contributed by grand_master


C#
// C# Program to find nth
// centered dodecagonal number
using System;
class GFG{
 
// Function to calculate
// centered dodecagonal number
static long centeredDodecagonal(long n)
{
     
    // Formula to calculate nth
    // centered dodecagonal number
    return 6 * n * (n - 1) + 1;
}
 
// Driver Code
public static void Main(String[] args)
{
    long n = 2;
    Console.WriteLine(centeredDodecagonal(n));
     
    n = 9;
    Console.WriteLine(centeredDodecagonal(n));
}
}
 
// This code is contributed by shivanisinghss2110


Javascript


输出 :
13
433

参考
http://oeis.org/A003154