📜  五位环数

📅  最后修改于: 2021-10-23 09:05:59             🧑  作者: Mango

给定一个数 n,任务是编写一个程序来找出第 N 个五角环数。五角星数是一种比喻数,可以表示为规则和离散的几何图案。在帕斯卡三角形中,从右到左或从左到右的第 5 项行 1 4 6 4 1 开始的任何行的第五个单元格中的数字Pentatope number
例子 :

前几个 Pentatope 数是:
1、5、15、35、70、126、210、330、495、715、1001…………
第 N 个 Pentatope 数的公式:

\begin{math}  Ptop_{n}=(n(n+1)(n+2)(n+3))/24 \end{math}

C++
// C++ Program to find the
// nth Pentatope Number
#include 
using namespace std;
 
// Function that returns nth
// pentatope number
int pentatopeNum(int n)
{
    return (n * (n + 1) * (n + 2) * (n + 3)) / 24;
}
 
// Drivers Code
int main()
{
    // For 5th PentaTope Number
    int n = 5;
    cout << pentatopeNum(n) << endl;
 
    // For 11th PentaTope Number
    n = 11;
    cout << pentatopeNum(n) << endl;
 
    return 0;
}


Java
// Java Program to find the
// nth Pentatope Number
import java.io.*;
 
class GFG
{
     
// Function that returns nth
// pentatope number
static int pentatopeNum(int n)
{
    return (n * (n + 1) *
           (n + 2) * (n + 3)) / 24;
}
// Driver Code
public static void main (String[] args)
{
// For 5th PentaTope Number
int n = 5;
System.out.println(pentatopeNum(n));
 
// For 11th PentaTope Number
n = 11;
System.out.println(pentatopeNum(n));
 
}
}
 
// This code is contributed by m_kit


Python3
# Python3 program to find
# nth Pentatope number
 
# Function to calculate
# Pentatope number
def pentatopeNum(n):
 
    # Formula to calculate nth
    # Pentatope number
    return (n * (n + 1) *
                (n + 2) *
                (n + 3) // 24)
 
# Driver Code
n = 5
print(pentatopeNum(n))
n = 11
print(pentatopeNum(n))
 
# This code is contributed
# by ajit.


C#
// C# Program to find the
// nth Pentatope Number
using System;
 
class GFG
{
     
// Function that returns
// nth pentatope number
static int pentatopeNum(int n)
{
    return (n * (n + 1) *
           (n + 2) * (n + 3)) / 24;
}
 
// Driver Code
static public void Main(String []args)
{
     
// For 5th PentaTope Number
int n = 5;
 
Console.WriteLine(pentatopeNum(n));
 
// For 11th PentaTope Number
n = 11;
 
Console.WriteLine(pentatopeNum(n));
}
}
// This code is contributed by Arnab Kundu


PHP


Javascript


输出 :

70
1001

时间复杂度: O(1)
辅助空间: O(1)

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

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程