Posted on by Kalkicode
Code Number

Centered icosahedral number

A centered icosahedral number is a type of figurate number that can be represented visually as a three-dimensional shape resembling a 20-sided polyhedron called an icosahedron. These numbers are derived from a specific mathematical formula and hold interesting properties.

Problem Statement

The task is to write a C program to generate the first k centered icosahedral numbers and display the results. The centered icosahedral number sequence starts from 1 and follows a specific formula to calculate each subsequent number.

Explanation with Example

Let's take a value of k as 5 to understand the process of generating the first 5 centered icosahedral numbers.

  1. For n = 0:

    • Using the formula: (2n + 1) (5n² + 5n + 3) / 3
    • The result will be: (2 * 0 + 1) * (5 * (0 * 0) + 5 * 0 + 3) / 3 = 1
  2. For n = 1:

    • Using the formula: (2n + 1) (5n² + 5n + 3) / 3
    • The result will be: (2 * 1 + 1) * (5 * (1 * 1) + 5 * 1 + 3) / 3 = 13
  3. For n = 2:

    • Using the formula: (2n + 1) (5n² + 5n + 3) / 3
    • The result will be: (2 * 2 + 1) * (5 * (2 * 2) + 5 * 2 + 3) / 3 = 55
  4. For n = 3:

    • Using the formula: (2n + 1) (5n² + 5n + 3) / 3
    • The result will be: (2 * 3 + 1) * (5 * (3 * 3) + 5 * 3 + 3) / 3 = 147
  5. For n = 4:

    • Using the formula: (2n + 1) (5n² + 5n + 3) / 3
    • The result will be: (2 * 4 + 1) * (5 * (4 * 4) + 5 * 4 + 3) / 3 = 309

Therefore, the first 5 centered icosahedral numbers are 1, 13, 55, 147, and 309.

Pseudocode

centeredIcosahedralNo(k):
    for n from 0 to k-1:
        result = (2n + 1) * (5n² + 5n + 3) / 3
        print result

Algorithm

  1. Start the program and define the function centeredIcosahedralNo(k) that takes an integer k as input.
  2. Within the function, initialize a loop for variable n from 0 to k-1.
  3. For each iteration, calculate the centered icosahedral number using the formula result = (2n + 1) * (5n² + 5n + 3) / 3.
  4. Print the calculated result for each value of n in the loop.
  5. Return from the function.
  6. In the main() function, call centeredIcosahedralNo(10) to generate and display the first 10 centered icosahedral numbers.

Code Solution

Here given code implementation process.

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

void centeredIcosahedralNo(int k)
{
	// Print all initial k centered icosahedral number
	for (int n = 0; n < k; ++n)
	{
		//   Formula
		//   (2n + 1) (5n² + 5n + 3) 
		//   ——————————————————————
		//             3
      
		// Calculate nth icosahedral number
		int result = ((2 *n + 1) *(5 *(n *n) + 5 *n + 3)) / 3;
      
		// Display Calculated value
		printf("  %d", result);
	}
}
int main()
{
	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
	//  Test k = 10
	centeredIcosahedralNo(10);
	return 0;
}

Output

  1  13  55  147  309  561  923  1415  2057  2869
// Java program for
// Centered icosahedral number
public class CenteredIcosahedral
{
	public void centeredIcosahedralNo(int k)
	{
		// Print all initial k centered icosahedral number
		for (int n = 0; n < k; ++n)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			int result = ((2 * n + 1) * (5 * (n * n) + 5 * n + 3)) / 3;
          
			// Display Calculated value
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		CenteredIcosahedral task = new CenteredIcosahedral();
		// Centered icosahedral numbers are
		// —————————————————————————————————————————————
		//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
		//   2869, 3871, 5083, 6525 ... etc
		//  Test k = 10
		task.centeredIcosahedralNo(10);
	}
}

Output

 1 13 55 147 309 561 923 1415 2057 2869
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered icosahedral number

class CenteredIcosahedral
{
	public: void centeredIcosahedralNo(int k)
	{
		// Print all initial k centered icosahedral number
		for (int n = 0; n < k; ++n)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			int result = ((2 *n + 1) *(5 *(n *n) + 5 *n + 3)) / 3;
          
			// Display Calculated value
			cout << " " << result;
		}
	}
};
int main()
{
	CenteredIcosahedral *task = new CenteredIcosahedral();
	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
	//  Test k = 10
	task->centeredIcosahedralNo(10);
	return 0;
}

Output

 1 13 55 147 309 561 923 1415 2057 2869
// Include namespace system
using System;
// Csharp program for
// Centered icosahedral number
public class CenteredIcosahedral
{
	public void centeredIcosahedralNo(int k)
	{
		// Print all initial k centered icosahedral number
		for (int n = 0; n < k; ++n)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			int result = ((2 * n + 1) * (5 * (n * n) + 5 * n + 3)) / 3;
          
			// Display Calculated value
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		CenteredIcosahedral task = new CenteredIcosahedral();
		// Centered icosahedral numbers are
		// —————————————————————————————————————————————
		//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
		//   2869, 3871, 5083, 6525 ... etc
		//  Test k = 10
		task.centeredIcosahedralNo(10);
	}
}

Output

 1 13 55 147 309 561 923 1415 2057 2869
package main
import "fmt"
// Go program for
// Centered icosahedral number

func centeredIcosahedralNo(k int) {
	// Print all initial k centered icosahedral number
	for n := 0 ; n < k ; n++ {
		//   Formula
		//   (2n + 1) (5n² + 5n + 3) 
		//   ——————————————————————
		//             3
      
		// Calculate nth icosahedral number
		var result int = ((2 * n + 1) * 
                          (5 * (n * n) + 5 * n + 3)) / 3
      
		// Display Calculated value
		fmt.Print(" ", result)
	}
}
func main() {

	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
	
	//  Test k = 10
	centeredIcosahedralNo(10)
}

Output

 1 13 55 147 309 561 923 1415 2057 2869
<?php
// Php program for
// Centered icosahedral number
class CenteredIcosahedral
{
	public	function centeredIcosahedralNo($k)
	{
		// Print all initial k centered icosahedral number
		for ($n = 0; $n < $k; ++$n)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			$result = (int)(((2 * $n + 1) * 
                             (5 * ($n * $n) + 5 * $n + 3)) / 3);
          
			// Display Calculated value
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new CenteredIcosahedral();
	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
	//  Test k = 10
	$task->centeredIcosahedralNo(10);
}
main();

Output

 1 13 55 147 309 561 923 1415 2057 2869
// Node JS program for
// Centered icosahedral number
class CenteredIcosahedral
{
	centeredIcosahedralNo(k)
	{
		// Print all initial k centered icosahedral number
		for (var n = 0; n < k; ++n)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
			// Calculate nth icosahedral number
			var result = parseInt(((2 * n + 1) * 
                                   (5 * (n * n) + 5 * n + 3)) / 3);
			// Display Calculated value
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new CenteredIcosahedral();
	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
	//  Test k = 10
	task.centeredIcosahedralNo(10);
}
main();

Output

 1 13 55 147 309 561 923 1415 2057 2869
#  Python 3 program for
#  Centered icosahedral number
class CenteredIcosahedral :
	def centeredIcosahedralNo(self, k) :
		n = 0
		#  Print all initial k centered icosahedral number
		while (n < k) :
			#    Formula
			#    (2n + 1) (5n² + 5n + 3) 
			#    ——————————————————————
			#              3
			#  Calculate nth icosahedral number
			result = int(((2 * n + 1) * 
                          (5 * (n * n) + 5 * n + 3)) / 3)
			#  Display Calculated value
			print(" ", result, end = "")
			n += 1
		
	

def main() :
	task = CenteredIcosahedral()
	#  Centered icosahedral numbers are
	#  —————————————————————————————————————————————
	#    1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	#    2869, 3871, 5083, 6525 ... etc
	#   Test k = 10
	task.centeredIcosahedralNo(10)

if __name__ == "__main__": main()

Output

  1  13  55  147  309  561  923  1415  2057  2869
#  Ruby program for
#  Centered icosahedral number
class CenteredIcosahedral 
	def centeredIcosahedralNo(k) 
		n = 0
		#  Print all initial k centered icosahedral number
		while (n < k) 
			#    Formula
			#    (2n + 1) (5n² + 5n + 3) 
			#    ——————————————————————
			#              3
            
			#  Calculate nth icosahedral number
			result = ((2 * n + 1) * (5 * (n * n) + 5 * n + 3)) / 3

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

	end

end

def main() 
	task = CenteredIcosahedral.new()
	#  Centered icosahedral numbers are
	#  —————————————————————————————————————————————
	#    1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	#    2869, 3871, 5083, 6525 ... etc
    
	#   Test k = 10
	task.centeredIcosahedralNo(10)
end

main()

Output

 1 13 55 147 309 561 923 1415 2057 2869
// Scala program for
// Centered icosahedral number
class CenteredIcosahedral()
{
	def centeredIcosahedralNo(k: Int): Unit = {
		var n: Int = 0;
		// Print all initial k centered icosahedral number
		while (n < k)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			var result: Int = ((2 * n + 1) * 
                               (5 * (n * n) + 5 * n + 3)) / 3;
          
			// Display Calculated value
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: CenteredIcosahedral = new CenteredIcosahedral();
		// Centered icosahedral numbers are
		// —————————————————————————————————————————————
		//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
		//   2869, 3871, 5083, 6525 ... etc
  
		//  Test k = 10
		task.centeredIcosahedralNo(10);
	}
}

Output

 1 13 55 147 309 561 923 1415 2057 2869
// Swift 4 program for
// Centered icosahedral number
class CenteredIcosahedral
{
	func centeredIcosahedralNo(_ k: Int)
	{
		var n: Int = 0;
		// Print all initial k centered icosahedral number
		while (n < k)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			let result: Int = ((2 * n + 1) * 
                               (5 * (n * n) + 5 * n + 3)) / 3;
          
			// Display Calculated value
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: CenteredIcosahedral = CenteredIcosahedral();
	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
  
	//  Test k = 10
	task.centeredIcosahedralNo(10);
}
main();

Output

  1  13  55  147  309  561  923  1415  2057  2869
// Kotlin program for
// Centered icosahedral number
class CenteredIcosahedral
{
	fun centeredIcosahedralNo(k: Int): Unit
	{
		var n: Int = 0;
		// Print all initial k centered icosahedral number
		while (n < k)
		{
			//   Formula
			//   (2n + 1) (5n² + 5n + 3) 
			//   ——————————————————————
			//             3
          
			// Calculate nth icosahedral number
			val result: Int = ((2 * n + 1) * 
                               (5 * (n * n) + 5 * n + 3)) / 3;
          
			// Display Calculated value
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: CenteredIcosahedral = CenteredIcosahedral();
	// Centered icosahedral numbers are
	// —————————————————————————————————————————————
	//   1, 13, 55, 147, 309, 561, 923, 1415, 2057, 
	//   2869, 3871, 5083, 6525 ... etc
  
	//  Test k = 10
	task.centeredIcosahedralNo(10);
}

Output

 1 13 55 147 309 561 923 1415 2057 2869

Time Complexity

The time complexity of this algorithm is O(k), where k is the number of centered icosahedral numbers to be generated. The loop runs k times, and each iteration involves simple arithmetic operations that take constant time. Thus, the overall time complexity is linear with respect to k.

Result and Output Explanation

The provided C program generates the first 10 centered icosahedral numbers and displays the results. The output of the program is as follows:

Output: 1 13 55 147 309 561 923 1415 2057 2869

The output consists of the first 10 centered icosahedral numbers separated by spaces. The program successfully calculates these numbers using the given formula and displays them to the user.

Conclusion

This article explains the concept of centered icosahedral numbers, provides a C program to generate the first k centered icosahedral numbers, and includes a detailed explanation of the algorithm and time complexity. The program efficiently calculates the numbers and displays them to the user. Centered icosahedral numbers are an interesting topic in mathematics and have applications in various fields.

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