Dado un número n, la tarea es escribir un programa para encontrar el enésimo número de pentátopo. Un número de pentátopo es una clase de número figurativo y se puede representar como patrones geométricos regulares y discretos. En el triángulo pascal, el número en la quinta celda de cualquier fila que comience con el quinto término fila 1 4 6 4 1 de derecha a izquierda o de izquierda a derecha es el número del pentátopo .
Ejemplos:
Entrada: 5
Salida: 70
Entrada: 8
Salida: 1001
Los primeros números del pentátopo son:
1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001………
Fórmula para el enésimo número del pentátopo:
C++
// C++ Program to find the // nth Pentatope Number #include <bits/stdc++.h> 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; }
C
// C Program to find the // nth Pentatope Number #include <stdio.h> // 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; printf("%d\n",pentatopeNum(n)); // For 11th PentaTope Number n = 11; printf("%d\n",pentatopeNum(n)); return 0; } // This code is contributed by kothavvsaakash.
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
<?php // PHP Program to find the // nth Pentatope Number // Function that returns // nth pentatope number function pentatopeNum($n) { return ($n * ($n + 1) * ($n + 2) * ($n + 3)) / 24; } // Driver Code // For 5th PentaTope Number $n = 5; echo pentatopeNum($n), "\n"; // For 11th PentaTope Number $n = 11; echo pentatopeNum($n), "\n" ; // This code is contributed // by aj_36 ?>
Javascript
<script> // Javascript Program to find the // nth Pentatope Number // Function that returns // nth pentatope number function pentatopeNum(n) { return (n * (n + 1) * (n + 2) * (n + 3)) / 24; } // Driver Code // For 5th PentaTope Number let n = 5; document.write( pentatopeNum(n)+"<br>"); // For 11th PentaTope Number n = 11; document.write( pentatopeNum(n)); // This code is contributed by sravan kumar </script>
Producción :
70 1001
Complejidad de tiempo: O(1)
Espacio auxiliar: O(1)
Referencia: https://en.wikipedia.org/wiki/Pentatope_number