Posted on by Kalkicode
Code Number

# Icosahedral number

An icosahedral number is a special type of figurate number that represents the number of spheres required to form a regular icosahedron (a polyhedron with 20 equilateral triangular faces). It is calculated using a specific formula that relates to the number of spheres stacked together in layers to form the icosahedron. In this article, we will explore the concept of icosahedral numbers, provide a suitable example to illustrate the concept, and then present a C program to generate and print the initial k icosahedral numbers.

## Problem Statement

Given a positive integer k, the task is to calculate and print the first k icosahedral numbers using the formula: n(5n^2 - 5n + 2) / 2, where 'n' represents the number of layers of spheres forming the icosahedron.

## Suitable Example

Let's take k = 5 to illustrate the concept of icosahedral numbers. We need to calculate and print the first 5 icosahedral numbers.

Icosahedral numbers: 1, 12, 48, 124, 255, ...

## Explanation

1. For n = 1: Icosahedral number = 1(51^2 - 51 + 2) / 2 = 1(5 - 5 + 2) / 2 = 1(2) / 2 = 1

2. For n = 2: Icosahedral number = 2(52^2 - 52 + 2) / 2 = 2(20 - 10 + 2) / 2 = 2(12) / 2 = 12

3. For n = 3: Icosahedral number = 3(53^2 - 53 + 2) / 2 = 3(45 - 15 + 2) / 2 = 3(32) / 2 = 48

4. For n = 4: Icosahedral number = 4(54^2 - 54 + 2) / 2 = 4(80 - 20 + 2) / 2 = 4(62) / 2 = 124

5. For n = 5: Icosahedral number = 5(55^2 - 55 + 2) / 2 = 5(125 - 25 + 2) / 2 = 5(102) / 2 = 255

Hence, the first 5 icosahedral numbers are 1, 12, 48, 124, and 255.

## Standard Pseudocode

``````function icosahedralNumber(k):
for n from 1 to k:
result = n * (5 * n^2 - 5 * n + 2) / 2
print result
``````

## Algorithm Explanation

1. Start the icosahedralNumber function with the parameter k, which represents the number of icosahedral numbers to be calculated.
2. Iterate from n = 1 to n = k.
3. Calculate the icosahedral number for each n using the formula (n * (5 * n^2 - 5 * n + 2)) / 2.
4. Print the calculated icosahedral number for each n.

Code Explanation:

1. The main function initializes k as 10 and calls the icosahedralNo function with k as an argument.
2. The icosahedralNo function takes an integer k as input.
3. Inside the function, a loop runs from n = 1 to n = k.
4. For each iteration, the icosahedral number is calculated using the formula and stored in the variable 'result.'
5. The calculated 'result' is then printed on the console.

## Code Solution

Here given code implementation process.

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

void icosahedralNo(int k)
{
// Print all initial k icosahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
int result = (n *(5 *(n *n) - 5 *n + 2)) / 2;

// Display calculated result
printf("  %d", result);
}
}
int main()
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
icosahedralNo(10);
return 0;
}``````

#### Output

``  1  12  48  124  255  456  742  1128  1629  2260``
``````// Java program for
// Icosahedral number
public class IcosahedralNumber
{
public void icosahedralNo(int k)
{
// Print all initial k icosahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
int result = (n * (5 * (n * n) - 5 * n + 2)) / 2;

// Display calculated result
System.out.print(" " + result);
}
}
public static void main(String[] args)
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
}
}``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Icosahedral number

class IcosahedralNumber
{
public: void icosahedralNo(int k)
{
// Print all initial k icosahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
int result = (n *(5 *(n *n) - 5 *n + 2)) / 2;

// Display calculated result
cout << " " << result;
}
}
};
int main()
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
return 0;
}``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````// Include namespace system
using System;
// Csharp program for
// Icosahedral number
public class IcosahedralNumber
{
public void icosahedralNo(int k)
{
// Print all initial k icosahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
int result = (n * (5 * (n * n) - 5 * n + 2)) / 2;

// Display calculated result
Console.Write(" " + result);
}
}
public static void Main(String[] args)
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
}
}``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````package main
import "fmt"
// Go program for
// Icosahedral number

func icosahedralNo(k int) {
// Print all initial k icosahedral number
for n := 1 ; n <= k ; n++ {
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
var result int = (n * (5 * (n * n) - 5 * n + 2)) / 2

// Display calculated result
fmt.Print(" ", result)
}
}
func main() {

//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
icosahedralNo(10)
}``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````<?php
// Php program for
// Icosahedral number
class IcosahedralNumber
{
public	function icosahedralNo(\$k)
{
// Print all initial k icosahedral number
for (\$n = 1; \$n <= \$k; ++\$n)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2
// Calculate nth icosahedral number
\$result = (int)((\$n * (5 * (\$n * \$n) - 5 * \$n + 2)) / 2);
// Display calculated result
echo(" ".\$result);
}
}
}

function main()
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
}
main();``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````// Node JS program for
// Icosahedral number
class IcosahedralNumber
{
icosahedralNo(k)
{
// Print all initial k icosahedral number
for (var n = 1; n <= k; ++n)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
var result = parseInt((n * (5 * (n * n) - 5 * n + 2)) / 2);

// Display calculated result
process.stdout.write(" " + result);
}
}
}

function main()
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
}
main();``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````#  Python 3 program for
#  Icosahedral number
class IcosahedralNumber :
def icosahedralNo(self, k) :
n = 1
#  Print all initial k icosahedral number
while (n <= k) :
#  Formula
#   n(5n²-5n+2)
#  ——————————————
#        2

#  Calculate nth icosahedral number
result = int((n * (5 * (n * n) - 5 * n + 2)) / 2)

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

def main() :
#   Icosahedral number are
#  —————————————————————————————————————————————
#   1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
#   3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
#   16264, 19020, 22071, 25432, 29118, 33144, 37525,
#   42276, 47412, 52948, 58899, 65280, 72106,
#   79392, 87153, 95404 ... etc

#  k = 10

if __name__ == "__main__": main()``````

#### Output

``  1  12  48  124  255  456  742  1128  1629  2260``
``````#  Ruby program for
#  Icosahedral number
class IcosahedralNumber
def icosahedralNo(k)
n = 1
#  Print all initial k icosahedral number
while (n <= k)
#  Formula
#   n(5n²-5n+2)
#  ——————————————
#        2

#  Calculate nth icosahedral number
result = (n * (5 * (n * n) - 5 * n + 2)) / 2

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

end

end

def main()
#   Icosahedral number are
#  —————————————————————————————————————————————
#   1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
#   3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
#   16264, 19020, 22071, 25432, 29118, 33144, 37525,
#   42276, 47412, 52948, 58899, 65280, 72106,
#   79392, 87153, 95404 ... etc
#  k = 10
end

main()``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````// Scala program for
// Icosahedral number
class IcosahedralNumber()
{
def icosahedralNo(k: Int): Unit = {
var n: Int = 1;
// Print all initial k icosahedral number
while (n <= k)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
var result: Int = (n * (5 * (n * n) - 5 * n + 2)) / 2;

// Display calculated result
print(" " + result);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: IcosahedralNumber = new IcosahedralNumber();
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc
// k = 10
}
}``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``
``````// Swift 4 program for
// Icosahedral number
class IcosahedralNumber
{
func icosahedralNo(_ k: Int)
{
var n: Int = 1;
// Print all initial k icosahedral number
while (n <= k)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
let result: Int = (n * (5 * (n * n) - 5 * n + 2)) / 2;

// Display calculated result
print(" ", result, terminator: "");
n += 1;
}
}
}
func main()
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
}
main();``````

#### Output

``  1  12  48  124  255  456  742  1128  1629  2260``
``````// Kotlin program for
// Icosahedral number
class IcosahedralNumber
{
fun icosahedralNo(k: Int): Unit
{
var n: Int = 1;
// Print all initial k icosahedral number
while (n <= k)
{
// Formula
//  n(5n²-5n+2)
// ——————————————
//       2

// Calculate nth icosahedral number
val result: Int = (n * (5 * (n * n) - 5 * n + 2)) / 2;

// Display calculated result
print(" " + result);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
//  Icosahedral number are
// —————————————————————————————————————————————
//  1, 12, 48, 124, 255, 456, 742, 1128, 1629, 2260 ,
//  3036, 3972, 5083, 6384, 7890, 9616, 11577, 13788,
//  16264, 19020, 22071, 25432, 29118, 33144, 37525,
//  42276, 47412, 52948, 58899, 65280, 72106,
//  79392, 87153, 95404 ... etc

// k = 10
}``````

#### Output

`` 1 12 48 124 255 456 742 1128 1629 2260``

## Resultant Output Explanation

The output of the given C program is: "1 12 48 124 255 456 742 1128 1629 2260".

## Time Complexity

The time complexity of the icosahedralNo function mainly depends on the loop that runs from n = 1 to n = k. Hence, the time complexity can be expressed as O(k). In this specific implementation, k is set to 10, so the time complexity is constant or O(1).

In this article, we discussed the concept of icosahedral numbers, which represent the number of spheres required to form an icosahedron. We provided a suitable example to explain the concept, followed by the standard pseudocode and algorithm for generating and printing the initial k icosahedral numbers. We also analyzed the provided C code and explained its output. Overall, icosahedral numbers are an interesting mathematical concept with various applications in geometry and crystallography.

## 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.

Categories
Relative Post