📜  七边形数

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

给定数字n,任务是找到第n个七边形数。
七十进制数是数字的类别。它有十七面的多边形,称为七边形。第n个七边形数的计数是点的十七个数,所有其他点都围绕着一个公共的共享角并形成一个图案。

例子:

七边形数
计算第n个七边形数的公式:

  \begin{math}  Hp_{n}=(15n^2-13n)/2 \end{math}

C++
// C++ program to find Nth
// heptadecagonal number
#include 
using namespace std;
  
// Function to calculate heptadecagonal
// number
int heptadecagonalNum(long int n)
{
    return ((15 * n * n) - 13 * n) / 2;
}
  
// Driver Code
int main()
{
    long int n = 3;
    cout << n << "th Heptadecagonal number : ";
    cout << heptadecagonalNum(n);
    cout << endl;
    n = 8;
    cout << n << "th Heptadecagonal number : ";
    cout << heptadecagonalNum(n);
  
    return 0;
}


Java
// Java program to find Nth heptadecagonal number
import java.io.*;
  
class GFG {
      
    // Function to calculate heptadecagonal
    // number
    static long heptadecagonalNum(long n)
    {
        return ((15 * n * n) - 13 * n) / 2;
    }
      
    // Driver Code
    public static void main (String[] args)
    {
        long n = 3;
        System.out.print( n + "th Heptadecagonal" 
                                 + " number : ");
        System.out.println( heptadecagonalNum(n));
          
        n = 8;
        System.out.print( n + "th Heptadecagonal"
                                 + " number : ");
        System.out.print( heptadecagonalNum(n));
    }
}
  
// This code is contributed by anuj_67.


Python3
# Python program to find Nth
# heptadecagonal number
  
# Function to calculate
# heptadecagonal number
def heptadecagonalNum(n):
  
    # Formula to calculate nth
    # heptadecagonal number
    return ((15 * n * n) - 13 * n) // 2
  
  
# Driver Code
n = 3
print("%sth Heptadecagonal number : " %n,
                    heptadecagonalNum(n))
n = 8
print("%sth Heptadecagonal number: " %n,
                    heptadecagonalNum(n))
                      
                      
# This code is contributed by ajit


C#
// C# program to find Nth 
// heptadecagonal number
using System;
class GFG {
      
    // Function to calculate 
    // heptadecagonal number
    static long heptadecagonalNum(long n)
    {
        return ((15 * n * n) - 
                  13 * n) / 2;
    }
      
    // Driver Code
    public static void Main ()
    {
        long n = 3;
        Console.Write( n + "th Heptadecagonal"
                                + " number : ");
        Console.WriteLine( heptadecagonalNum(n));
          
        n = 8;
        Console.Write( n + "th Heptadecagonal"
                                + " number : ");
        Console.WriteLine( heptadecagonalNum(n));
    }
}
  
// This code is contributed by anuj_67.


PHP


输出

3th Heptadecagonal number : 48
8th Heptadecagonal number : 428

参考:https://en.wikipedia.org/wiki/Polygonal_number