Posted on by Kalkicode
Code Number

Pentatope number

The pentatope number is a sequence of numbers that represents the number of ways five distinct points in a 4-dimensional space can be connected. In other words, it is the number of 4-dimensional simplices that can be formed using five vertices. The pentatope numbers are a subset of the larger category of figurate numbers, which have practical applications in various fields such as mathematics, physics, and computer graphics.

Problem Statement

The task is to write a program to generate the first 'k' pentatope numbers and display them as output. The formula to calculate the nth pentatope number is given by (n * (n + 1) * (n + 2) * (n + 3)) / 24.

Example

Let's take k = 5 to demonstrate the calculation of the first five pentatope numbers

  • For n = 1, the pentatope number is (1 * 2 * 3 * 4) / 24 = 1
  • For n = 2, the pentatope number is (2 * 3 * 4 * 5) / 24 = 5
  • For n = 3, the pentatope number is (3 * 4 * 5 * 6) / 24 = 15
  • For n = 4, the pentatope number is (4 * 5 * 6 * 7) / 24 = 35
  • For n = 5, the pentatope number is (5 * 6 * 7 * 8) / 24 = 70

Standard Pseudocode

pentatopeNo(k)
    for n = 1 to k
      result = (n * (n + 1) * (n + 2) * (n + 3)) / 24
      print result
    end for
  end function
  

Algorithm Explanation

  1. Start the function pentatopeNo with a parameter 'k' that represents the number of pentatope numbers to generate.
  2. Within the function, use a loop to iterate from 1 to k.
  3. For each value of 'n' in the loop, calculate the corresponding pentatope number using the formula mentioned earlier.
  4. Print the calculated result for each 'n' in the loop.
  5. Exit the function.

Code Solution

Here given code implementation process.

// C Program for
// Pentatope number
#include <stdio.h>

void pentatopeNo(int k)
{
	// Print all initial k pentatope number
	for (int n = 1; n <= k; ++n)
	{
		// Formula
		// (n (n + 1) (n + 2) (n + 3)) / 24
      
		// Calculate nth pentatope number
		int result = n *(n + 1) *(n + 2) *(n + 3) / 24;
      
		// Display calculated result
		printf("  %d", result);
	}
}
int main()
{
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	pentatopeNo(10);
	return 0;
}

Output

  1  5  15  35  70  126  210  330  495  715
// Java program for
// Pentatope number 
public class PentatopeNumber
{
	public void pentatopeNo(int k)
	{
		// Print all initial k pentatope number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			int result = n * (n + 1) * (n + 2) * (n + 3) / 24;
          
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		PentatopeNumber task = new PentatopeNumber();
		//  Pentatope number are
		// —————————————————————————————————————————————
		// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
		// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
		// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
		// 27405, 31465, 35960, 40920, 46376, 52360, 
		// 58905, 66045, 73815, 82251, 91390 etc.
      
		// k = 10
		task.pentatopeNo(10);
	}
}

Output

 1 5 15 35 70 126 210 330 495 715
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Pentatope number 

class PentatopeNumber
{
	public: void pentatopeNo(int k)
	{
		// Print all initial k pentatope number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			int result = n *(n + 1) *(n + 2) *(n + 3) / 24;
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	PentatopeNumber *task = new PentatopeNumber();
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	task->pentatopeNo(10);
	return 0;
}

Output

 1 5 15 35 70 126 210 330 495 715
// Include namespace system
using System;
// Csharp program for
// Pentatope number 
public class PentatopeNumber
{
	public void pentatopeNo(int k)
	{
		// Print all initial k pentatope number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			int result = n * (n + 1) * (n + 2) * (n + 3) / 24;
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		PentatopeNumber task = new PentatopeNumber();
		//  Pentatope number are
		// —————————————————————————————————————————————
		// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
		// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
		// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
		// 27405, 31465, 35960, 40920, 46376, 52360, 
		// 58905, 66045, 73815, 82251, 91390 etc.
      
		// k = 10
		task.pentatopeNo(10);
	}
}

Output

 1 5 15 35 70 126 210 330 495 715
package main
import "fmt"
// Go program for
// Pentatope number 

func pentatopeNo(k int) {
	// Print all initial k pentatope number
	for n := 1 ; n <= k ; n++ {
		// Formula
		// (n (n + 1) (n + 2) (n + 3)) / 24
      
		// Calculate nth pentatope number
		var result int = n * (n + 1) * 
          (n + 2) * (n + 3) / 24
      
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {
	
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	pentatopeNo(10)
}

Output

 1 5 15 35 70 126 210 330 495 715
<?php
// Php program for
// Pentatope number 
class PentatopeNumber
{
	public	function pentatopeNo($k)
	{
		// Print all initial k pentatope number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			$result = (int)($n * ($n + 1) * 
                            ($n + 2) * ($n + 3) / 24);
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new PentatopeNumber();
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	$task->pentatopeNo(10);
}
main();

Output

 1 5 15 35 70 126 210 330 495 715
// Node JS program for
// Pentatope number 
class PentatopeNumber
{
	pentatopeNo(k)
	{
		// Print all initial k pentatope number
		for (var n = 1; n <= k; ++n)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			var result = parseInt(n * (n + 1) * 
                                  (n + 2) * (n + 3) / 24);
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new PentatopeNumber();
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	task.pentatopeNo(10);
}
main();

Output

 1 5 15 35 70 126 210 330 495 715
#  Python 3 program for
#  Pentatope number 
class PentatopeNumber :
	def pentatopeNo(self, k) :
		n = 1
		#  Print all initial k pentatope number
		while (n <= k) :
			#  Formula
			#  (n (n + 1) (n + 2) (n + 3)) / 24
            
			#  Calculate nth pentatope number
			result = int(n * (n + 1) * 
                         (n + 2) * (n + 3) / 24)
			#  Display calculated result
			print(" ", result, end = "")
			n += 1
		
	

def main() :
	task = PentatopeNumber()
	#   Pentatope number are
	#  —————————————————————————————————————————————
	#  1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	#  1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	#  8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	#  27405, 31465, 35960, 40920, 46376, 52360, 
	#  58905, 66045, 73815, 82251, 91390 etc.
    
	#  k = 10
	task.pentatopeNo(10)

if __name__ == "__main__": main()

Output

  1  5  15  35  70  126  210  330  495  715
#  Ruby program for
#  Pentatope number 
class PentatopeNumber 
	def pentatopeNo(k) 
		n = 1
		#  Print all initial k pentatope number
		while (n <= k) 
			#  Formula
			#  (n (n + 1) (n + 2) (n + 3)) / 24
            
			#  Calculate nth pentatope number
			result = n * (n + 1) * (n + 2) * (n + 3) / 24

			#  Display calculated result
			print(" ", result)
			n += 1
		end

	end

end

def main() 
	task = PentatopeNumber.new()
	#   Pentatope number are
	#  —————————————————————————————————————————————
	#  1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	#  1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	#  8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	#  27405, 31465, 35960, 40920, 46376, 52360, 
	#  58905, 66045, 73815, 82251, 91390 etc.
    
	#  k = 10
	task.pentatopeNo(10)
end

main()

Output

 1 5 15 35 70 126 210 330 495 715
// Scala program for
// Pentatope number 
class PentatopeNumber()
{
	def pentatopeNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k pentatope number
		while (n <= k)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			var result: Int = n * (n + 1) * 
              (n + 2) * (n + 3) / 24;
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: PentatopeNumber = new PentatopeNumber();
		//  Pentatope number are
		// —————————————————————————————————————————————
		// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
		// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
		// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
		// 27405, 31465, 35960, 40920, 46376, 52360, 
		// 58905, 66045, 73815, 82251, 91390 etc.
  
		// k = 10
		task.pentatopeNo(10);
	}
}

Output

 1 5 15 35 70 126 210 330 495 715
// Swift 4 program for
// Pentatope number 
class PentatopeNumber
{
	func pentatopeNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k pentatope number
		while (n <= k)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			let result: Int = n * (n + 1) * 
              (n + 2) * (n + 3) / 24;
          
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: PentatopeNumber = PentatopeNumber();
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	task.pentatopeNo(10);
}
main();

Output

  1  5  15  35  70  126  210  330  495  715
// Kotlin program for
// Pentatope number 
class PentatopeNumber
{
	fun pentatopeNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k pentatope number
		while (n <= k)
		{
			// Formula
			// (n (n + 1) (n + 2) (n + 3)) / 24
          
			// Calculate nth pentatope number
			val result: Int = n * (n + 1) * 
              (n + 2) * (n + 3) / 24;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: PentatopeNumber = PentatopeNumber();
	//  Pentatope number are
	// —————————————————————————————————————————————
	// 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 
	// 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 
	// 8855, 10626, 12650, 14950, 17550, 20475, 23751, 
	// 27405, 31465, 35960, 40920, 46376, 52360, 
	// 58905, 66045, 73815, 82251, 91390 etc.
  
	// k = 10
	task.pentatopeNo(10);
}

Output

 1 5 15 35 70 126 210 330 495 715

Resultant Output Explanation

For the given code with k = 10, the output will be the first ten pentatope numbers: 1, 5, 15, 35, 70, 126, 210, 330, 495, and 715.

Time Complexity

The time complexity of the provided code is O(k) because the loop runs 'k' times, and all other operations (calculations and printing) inside the loop take constant time. As 'k' increases, the number of iterations grows linearly.

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment