 Open in App
Not now

# Centered tetrahedral number

• Last Updated : 19 May, 2022

We are given integer n, we need to find n-th centered tetrahedral number.
Description: The centered tetrahedral number is a centered figurate number that represents a tetrahedron.
Tetrahedral Numbers: A number is termed as a tetrahedral number if it can be represented as a pyramid with a triangular base and three sides, called a tetrahedron. The nth tetrahedral number is the sum of the first n triangular numbers
The first few centered tetrahedral number series are:
1, 5, 15, 35, 69, 121, 195, 295, 425, 589……………………….
Mathematical nth Term of centered tetrahedral number: Examples :

Input : n = 3
Output : 35

Input : n = 9
Output : 589

Below is the implementation of above formula.

## C++

 // C++ Program to find nth// Centered tetrahedral number#include using namespace std; // Function to find centered// Centered tetrahedral numberint centeredTetrahedralNumber(int n){    // Formula to calculate nth    // Centered tetrahedral number    // and return it into main function.    return (2 * n + 1) * (n * n + n + 3) / 3;} // Driver Codeint main(){    int n = 6;     cout << centeredTetrahedralNumber(n);     return 0;}

## C

 // C Program to find nth// Centered tetrahedral number#include  // Function to find centered// Centered tetrahedral numberint centeredTetrahedralNumber(int n){    // Formula to calculate nth    // Centered tetrahedral number    // and return it into main function.    return (2 * n + 1) * (n * n + n + 3) / 3;} // Driver Codeint main(){    int n = 6;         printf("%d",centeredTetrahedralNumber(n));     return 0;} // This code is contributed by kothavvsaakash.

## Java

 // Java Program to find nth Centered// tetrahedral numberimport java.io.*; class GFG {     // Function to find centered    // Centered tetrahedral number    static int centeredTetrahedralNumber(int n)    {                 // Formula to calculate nth        // Centered tetrahedral number        // and return it into main function.        return (2 * n + 1) * (n * n + n + 3) / 3;    }         // Driver Code      public static void main (String[] args)    {        int n = 6;         System.out.println(                   centeredTetrahedralNumber(n));    }} // This code is contributed by anuj_67.

## Python3

 # Python program to find nth# Centered tetrahedral number # Function to calculate# Centered tetrahedral number def centeredTetrahedralNumber(n):     # Formula to calculate nth    # Centered tetrahedral number    # and return it into main function         return (2 * n + 1) * (n * n + n + 3) // 3 # Driver Coden = 6print(centeredTetrahedralNumber(n))                     # This code is contributed by ajit

## C#

 // C# Program to find nth Centered// tetrahedral numberusing System; class GFG {     // Function to find centered    // Centered tetrahedral number    static int centeredTetrahedralNumber(int n)    {                 // Formula to calculate nth        // Centered tetrahedral number        // and return it into main function.        return (2 * n + 1) * (n * n + n + 3) / 3;    }         // Driver Code      public static void Main ()    {        int n = 6;         Console.WriteLine(                centeredTetrahedralNumber(n));    }} // This code is contributed by anuj_67.

## PHP

 

## Javascript

 

Output :

195

Time Complexity: O(1)
Auxiliary Space: O(1)

My Personal Notes arrow_drop_up