📜  五角位数

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

给定数字n,找到第n个五角位数字。五角形数字由帕斯卡三角形的任何一行中的第五个数字表示。由于它是第五个数字,因此应从至少包含5个数字的行开始。因此,它从第1 4 6 4行开始。第n个五位数的公式为: n(n + 1)(n + 2)(n + 3)/ 24
五角星的起始编号是:1、5、15、35、70、126、210、330、495…..
五角位数字:

五角位数字

在上图中,带红色圆圈的数字是五角星形数字。
例子:

Input : 4
Output : 35

Input : 8
Output : 330

以下是第n个五角位编号的实现:

C++
// CPP Program to find the
// nth Pentatope number
#include 
using namespace std;
 
// function for Pentatope
// number
int Pentatope_number(int n)
{
    // formula for find Pentatope
    // nth term
    return n * (n + 1) * (n + 2) * (n + 3) / 24;
}
 
// Driver Code
int main()
{
    int n = 7;
    cout << n << "th Pentatope number :"
         << Pentatope_number(n) << endl;
 
    n = 12;
    cout << n << "th Pentatope number :"
         << Pentatope_number(n) << endl;
 
    return 0;
}


Java
// Java Program to find the nth Pentatope
// number
import java.io.*;
 
class GFG {
 
    // function for Pentatope
    // number
    static int Pentatope_number(int n)
    {
         
        // formula for find Pentatope
        // nth term
        return n * (n + 1) * (n + 2) *
                         (n + 3) / 24;
    }
     
    // Driver Code
    public static void main (String[] args)
    {
        int n = 7;
        System.out.println( n + "th "
                   + "Pentatope number :"
                  + Pentatope_number(n));
                   
        n = 12;
        System.out.println( n + "th "
                  + "Pentatope number :"
                 + Pentatope_number(n));
    }
}
 
// This code is contributed by anuj_67.


Python3
# Python3 program to find
# nth Pentatope number
 
# Function to calculate
# Pentatope number
def Pentatope_number(n):
 
    # Formula to calculate nth
    # Pentatope number
    return (n * (n + 1) * (n + 2)
                 * (n + 3) // 24)
 
# Driver Code
n = 7
print("%sth Pentatope number : " %n,
                    Pentatope_number(n))
n = 12
print("%sth Pentatope number : " %n,
                    Pentatope_number(n))
 
# This code is contributed by ajit.


C#
// C# Program to find the nth Pentatope
// number
using System;
 
class GFG {
 
    // function for Pentatope
    // number
    static int Pentatope_number(int n)
    {
         
        // formula for find Pentatope
        // nth term
        return n * (n + 1) * (n + 2) *
                         (n + 3) / 24;
    }
     
    // Driver Code
    public static void Main ()
    {
        int n = 7;
        Console.WriteLine( n + "th "
                + "Pentatope number :"
               + Pentatope_number(n));
                
        n = 12;
        Console.WriteLine( n + "th "
                + "Pentatope number :"
               + Pentatope_number(n));
    }
}
 
// This code is contributed by anuj_67.


PHP


Javascript


输出 :

7th Pentatope number : 210
12th Pentatope number : 1365

参考资料: https : //en.wikipedia.org/wiki/Pentatope_number/