Triacontakaihenagonal number
Last Updated :
16 Jul, 2021
A triacontakaihenagonal number is a class of figurate numbers. It has 31 – sided polygon called triacontakaihenagon. The N-th triacontakaihenagonal number count’s the 31 number of dots and all other dots are surrounding with a common sharing corner and make a pattern.
The first few triacontakaihenagonol numbers are:
1, 31, 90, 178 …
Check if N is a triacontakaihenagonol number
Given a number N, the task is to find Nth triacontakaihenagonal number.
Examples:
Input: N = 2
Output: 31
Explanation:
The second triacontakaihenagonol number is 31.
Input: N = 3
Output: 90
Approach: In mathematics, the N-th triacontakaihenagonal number is given by the formula:
- Nth term of s sided polygon =
- Therefore Nth term of 31 sided polygon is
Below is the implementation of the above approach:
C++
#include <iostream>
using namespace std;
int triacontakaihenagonalNum( int n)
{
return (29 * n * n - 27 * n) / 2;
}
int main()
{
int n = 3;
cout << triacontakaihenagonalNum(n);
return 0;
}
|
Java
import java.util.*;
class GFG{
static int triacontakaihenagonalNum( int n)
{
return ( 29 * n * n - 27 * n) / 2 ;
}
public static void main (String[] args)
{
int n = 3 ;
System.out.print(triacontakaihenagonalNum(n));
}
}
|
Python3
def triacontakaihenagonalNum(n):
return ( 29 * n * n - 27 * n) / / 2 ;
n = 3 ;
print (triacontakaihenagonalNum(n));
|
C#
using System;
class GFG{
static int triacontakaihenagonalNum( int n)
{
return (29 * n * n - 27 * n) / 2;
}
public static void Main ( string [] args)
{
int n = 3;
Console.Write(triacontakaihenagonalNum(n));
}
}
|
Javascript
<script>
function triacontakaihenagonalNum( n)
{
return (29 * n * n - 27 * n) / 2;
}
let n = 3;
document.write(triacontakaihenagonalNum(n));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...