Given a number n, the task is to write a program to find Nth pentatope number. A pentatope number is class of figurative number and can be represented as regular and discrete geometric patterns. In pascal triangle’s the number in the fifth cell of any row starting with 5-th term row 1 4 6 4 1 from right to left or left to right is Pentatope number.
Examples :
Input : 5
Output :70
Input :8
Output :1001
First few Pentatope numbers are:
1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001………
Formula for Nth Pentatope number:
C++
#include <bits/stdc++.h>
using namespace std;
int pentatopeNum( int n)
{
return (n * (n + 1) * (n + 2) * (n + 3)) / 24;
}
int main()
{
int n = 5;
cout << pentatopeNum(n) << endl;
n = 11;
cout << pentatopeNum(n) << endl;
return 0;
}
|
C
#include <stdio.h>
int pentatopeNum( int n)
{
return (n * (n + 1) * (n + 2) * (n + 3)) / 24;
}
int main()
{
int n = 5;
printf ( "%d\n" ,pentatopeNum(n));
n = 11;
printf ( "%d\n" ,pentatopeNum(n));
return 0;
}
|
Java
import java.io.*;
class GFG
{
static int pentatopeNum( int n)
{
return (n * (n + 1 ) *
(n + 2 ) * (n + 3 )) / 24 ;
}
public static void main (String[] args)
{
int n = 5 ;
System.out.println(pentatopeNum(n));
n = 11 ;
System.out.println(pentatopeNum(n));
}
}
|
Python3
def pentatopeNum(n):
return (n * (n + 1 ) *
(n + 2 ) *
(n + 3 ) / / 24 )
n = 5
print (pentatopeNum(n))
n = 11
print (pentatopeNum(n))
|
C#
using System;
class GFG
{
static int pentatopeNum( int n)
{
return (n * (n + 1) *
(n + 2) * (n + 3)) / 24;
}
static public void Main(String []args)
{
int n = 5;
Console.WriteLine(pentatopeNum(n));
n = 11;
Console.WriteLine(pentatopeNum(n));
}
}
|
PHP
<?php
function pentatopeNum( $n )
{
return ( $n * ( $n + 1) *
( $n + 2) *
( $n + 3)) / 24;
}
$n = 5;
echo pentatopeNum( $n ), "\n" ;
$n = 11;
echo pentatopeNum( $n ), "\n" ;
?>
|
Javascript
<script>
function pentatopeNum(n)
{
return (n * (n + 1) *
(n + 2) *
(n + 3)) / 24;
}
let n = 5;
document.write( pentatopeNum(n)+ "<br>" );
n = 11;
document.write( pentatopeNum(n));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Reference:https://en.wikipedia.org/wiki/Pentatope_number
Contact Us