Centered tetrahedral number

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:

  \\ CTh_{n} = \frac{(2n+1)(n^2+n+3)}{3}  

Examples :

Input : n = 3
Output : 35

Input : n = 9
Output : 589

Below is the implementation of above formula.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ Program to find nth
// Centered tetrahedral number
#include <bits/stdc++.h>
using namespace std;
  
// Function to find centered
// Centered tetrahedral number
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
int main()
{
    int n = 6;
  
    cout << centeredTetrahedralNumber(n);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program to find nth Centered
// tetrahedral number
import 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.

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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 Code
n = 6
print(centeredTetrahedralNumber(n))
                      
# This code is contributed by ajit                 

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Program to find nth Centered
// tetrahedral number
using 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.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP Program to find nth
// Centered tetrahedral number
  
// Function to find centered
// Centered tetrahedral number
function 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 Code
$n = 6;
  
echo centeredTetrahedralNumber($n);
  
// This code is contributed by anuj_67.
?>

chevron_right


Output :

195


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : vt_m, jit_t



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.