Concentric Hexagonal Numbers
The following numbers form the concentric hexagonal sequence :
0, 1, 6, 13, 24, 37, 54, 73, 96, 121, 150 ……
The number sequence forms a pattern with concentric hexagons, and the numbers denote the number of points required after the n-th stage of the pattern.
Examples:
Input : N = 3
Output : 13
Input : N = 4
Output : 24
Approach :
The above series can be referred from Concentric Hexagonal Numbers.
Nth term of the series is 3*n2/2
Below is the implementation of the above approach :
C++
#include <bits/stdc++.h>
using namespace std;
int concentric_Hexagon( int n)
{
return 3 * pow (n, 2) / 2;
}
int main()
{
int n = 3;
cout << concentric_Hexagon(n);
return 0;
}
|
Java
class GFG
{
static int concentric_Haxagon( int n)
{
return 3 * ( int )Math.pow(n, 2 ) / 2 ;
}
public static void main (String[] args)
{
int n = 3 ;
System.out.println(concentric_Haxagon(n));
}
}
|
Python3
def concentric_Hexagon(n):
return 3 * pow (n, 2 ) / / 2
n = 3
print (concentric_Hexagon(n))
|
C#
using System;
class GFG
{
static int concentric_Hexagon( int n)
{
return 3 * ( int )Math.Pow(n, 2) / 2;
}
public static void Main()
{
int n = 3;
Console.WriteLine(concentric_Hexagon(n));
}
}
|
Javascript
<script>
function concentric_Haxagon(n)
{
return parseInt(3 * Math.pow(n, 2) / 2);
}
var n = 3;
document.write(concentric_Haxagon(n));
</script>
|
Time complexity: O(1) for given n, as it is doing constant operations.
Auxiliary Space: O(1)
Last Updated :
21 Sep, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...