Program for Centered Icosahedral Number
Last Updated :
03 Apr, 2023
We are given a number n, we need to find n-th centered Icosahedral number.
Description: A centered icosahedral number is a centered figurate number that represents an icosahedron.
The first few centered icosahedral number series are :
1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869, 3871, 5083, 6525, 8217……………….
Mathematical Formula for nth Centered icosahedral number:
Examples :
Input : n = 4
Output : 309
Input : n = 12
Output : 6525
Below is the implementation of the above formula
C++
#include <bits/stdc++.h>
using namespace std;
int centeredIcosahedralNum( int n)
{
return (2 * n + 1) * (5 * n * n + 5 * n + 3) / 3;
}
int main()
{
int n = 10;
cout << centeredIcosahedralNum(n) << endl;
n = 12;
cout << centeredIcosahedralNum(n) << endl;
return 0;
}
|
C
#include <stdio.h>
int centeredIcosahedralNum( int n)
{
return (2 * n + 1) * (5 * n * n + 5 * n + 3) / 3;
}
int main()
{
int n = 10;
printf ( "%d\n" ,centeredIcosahedralNum(n));
n = 12;
printf ( "%d\n" ,centeredIcosahedralNum(n));
return 0;
}
|
Java
import java.io.*;
class GFG {
static int centeredIcosahedralNum( int n)
{
return ( 2 * n + 1 ) * ( 5 * n * n +
5 * n + 3 ) / 3 ;
}
public static void main (String[] args)
{
int n = 10 ;
System.out.println(
centeredIcosahedralNum(n));
n = 12 ;
System.out.println(
centeredIcosahedralNum(n));
}
}
|
Python3
def centeredIcosahedralNum(n):
return (( 2 * n + 1 ) *
( 5 * n * n + 5 * n + 3 ) / / 3 )
n = 10
print (centeredIcosahedralNum(n))
n = 12
print (centeredIcosahedralNum(n))
|
C#
using System;
class GFG {
static int centeredIcosahedralNum( int n)
{
return (2 * n + 1) * (5 * n * n +
5 * n + 3) / 3;
}
public static void Main ()
{
int n = 10;
Console.WriteLine(
centeredIcosahedralNum(n));
n = 12;
Console.WriteLine(
centeredIcosahedralNum(n));
}
}
|
PHP
<?php
function centeredIcosahedralNum( $n )
{
return (2 * $n + 1) * (5 *
$n * $n + 5 * $n + 3) / 3;
}
$n = 10;
echo centeredIcosahedralNum( $n ), "\n" ;
$n = 12;
echo centeredIcosahedralNum( $n ), "\n" ;
?>
|
Javascript
<script>
function centeredIcosahedralNum(n)
{
return parseInt((2 * n + 1) * (5 * n * n + 5 * n + 3) / 3);
}
let n = 10;
document.write(centeredIcosahedralNum(n) + "<br>" );
n = 12;
document.write(centeredIcosahedralNum(n));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Reference:
https://en.wikipedia.org/wiki/Centered_icosahedral_number
Share your thoughts in the comments
Please Login to comment...