Given a number n, find the nth Pentatope number. A pentatope number is represented by the fifth number in any row of Pascal’s Triangle. As it is fifth number, it should start from row having at least 5 numbers. So, it starts from row 1 4 6 4 1. The formula for the nth pentatope number is: n (n+1) (n+2) (n+3) / 24Â
Starting Pentatope numbers are : 1, 5, 15, 35, 70, 126, 210, 330, 495…..
Pentatope Numbers:Â
Â
In the above figure, red color circled numbers are pentatope numbers.Â
Examples:Â
Input: 4
Output: 35Input: 8
Output: 330
Below is the implementation for nth Pentatope Number :
C++
// CPP Program to find the// nth Pentatope number#include <bits/stdc++.h>using namespace std;Â
// function for Pentatope// numberint Pentatope_number(int n){    // formula for find Pentatope    // nth term    return n * (n + 1) * (n + 2) * (n + 3) / 24;}Â
// Driver Codeint 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// numberimport 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 numberdef Pentatope_number(n):Â
    # Formula to calculate nth    # Pentatope number    return (n * (n + 1) * (n + 2)                  * (n + 3) // 24)Â
# Driver Coden = 7print("%sth Pentatope number : " %n,                    Pentatope_number(n))n = 12print("%sth Pentatope number : " %n,                    Pentatope_number(n))Â
# This code is contributed by ajit.    |
C#
// C# Program to find the nth Pentatope // numberusing 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
<?php// PHP Program to find the// nth Pentatope numberÂ
// function for Pentatope// numberfunction Pentatope_number($n){         // formula for find Pentatope    // nth term    return $n * ($n + 1) *           ($n + 2) * ($n + 3)                        / 24;}Â
    // Driver Code    $n = 7;    echo $n , "th Pentatope number :"            , Pentatope_number($n), "\n";Â
    $n = 12;    echo $n , "th Pentatope number :"            , Pentatope_number($n) ;             // This code is contributed by anuj_67.Â
?> |
Javascript
<script>Â
// Javascript Program to find the// nth Pentatope numberÂ
// function for Pentatope// numberfunction Pentatope_number(n){         // formula for find Pentatope    // nth term    return n * (n + 1) *(n + 2) * (n + 3)/ 24;}Â
    // Driver Code    let n = 7;    document.write( n + "th "                   + "Pentatope number : "                  + Pentatope_number(n)+"<br>") ;Â
     n = 12;    document.write( n + "th "                   + "Pentatope number : "                  + Pentatope_number(n)) ;             Â
// This code is contributed by sravan kumarÂ
</script> |
7th Pentatope number :210 12th Pentatope number :1365
Time complexity: O(1)
Auxiliary space: O(1)
References: https://en.wikipedia.org/wiki/Pentatope_number/
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!


… [Trackback]
[…] Here you will find 28004 more Information on that Topic: geeksforgeeks.org/pentatope-number/ […]
… [Trackback]
[…] Find More Information here to that Topic: geeksforgeeks.org/pentatope-number/ […]