Open In App

Triacontakaihenagonal number

Improve
Improve
Like Article
Like
Save
Share
Report

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 = \frac{((s-2)n^2 - (s-4)n)}{2}
     
  • Therefore Nth term of 31 sided polygon is 
     

Tn =\frac{((31-2)n^2 - (31-4)n)}{2} =\frac{(29n^2 - 27n)}{2}


  •  


Below is the implementation of the above approach:
 

C++

// C++ implementation for
// above approach
 
#include <iostream>
using namespace std;
 
// Function to find the Nth
// triacontakaihenagonal Number
int triacontakaihenagonalNum(int n)
{
    return (29 * n * n - 27 * n) / 2;
}
 
// Driver Code
int main()
{
    int n = 3;
    cout << triacontakaihenagonalNum(n);
 
    return 0;
}

                    

Java

// Java implementation for the
// above approach
import java.util.*;
 
class GFG{
 
// Function to find the Nth
// triacontakaihenagonal Number
static int triacontakaihenagonalNum(int n)
{
    return (29 * n * n - 27 * n) / 2;
}
 
// Driver Code
public static void main (String[] args)
{
     
    // Given number
    int n = 3;
 
    // Function call
    System.out.print(triacontakaihenagonalNum(n));
}
}
 
// This code is contributed by Ritik Bansal

                    

Python3

# Python3 implementation for
# above approach
 
# Function to find the Nth
# triacontakaihenagonal Number
def triacontakaihenagonalNum(n):
 
    return (29 * n * n - 27 * n) // 2;
 
# Driver Code
n = 3;
print(triacontakaihenagonalNum(n));
 
# This code is contributed by Code_Mech

                    

C#

// C# implementation for the
// above approach
using System;
  
class GFG{
  
// Function to find the Nth
// triacontakaihenagonal Number
static int triacontakaihenagonalNum(int n)
{
    return (29 * n * n - 27 * n) / 2;
}
  
// Driver Code
public static void Main (string[] args)
{
      
    // Given number
    int n = 3;
  
    // Function call
    Console.Write(triacontakaihenagonalNum(n));
}
}
  
// This code is contributed by rock_cool

                    

Javascript

<script>
// Javascript implementation for the
// above approach
 
    // Function to find the Nth
    // triacontakaihenagonal Number
    function triacontakaihenagonalNum( n)
    {
        return (29 * n * n - 27 * n) / 2;
    }
 
    // Driver Code
      
    // Given number
    let n = 3;
     
    // Function call
    document.write(triacontakaihenagonalNum(n));
 
// This code is contributed by Rajput-Ji
</script>

                    

Output: 
90

 

Time Complexity: O(1)

Auxiliary Space: O(1)



Last Updated : 16 Jul, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads