Nos dan el número entero n, necesitamos encontrar el número tetraédrico centrado en el n-ésimo.
Descripción: El número tetraédrico centrado es un número figurado centrado que representa un tetraedro.
Números tetraédricos: un número se denomina número tetraédrico si se puede representar como una pirámide con una base triangular y tres lados, llamada tetraedro. El enésimo número tetraédrico es la suma de los primeros n números triangulares .
Las primeras series de números tetraédricos centrados son:
1, 5, 15, 35, 69, 121, 195, 295, 425, 589……………………….
Enésimo término matemático del número tetraédrico centrado:
Ejemplos:
Input : n = 3 Output : 35 Input : n = 9 Output : 589
A continuación se muestra la implementación de la fórmula anterior.
C++
// 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; }
C
// C Program to find nth // Centered tetrahedral number #include <stdio.h> // 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; printf("%d",centeredTetrahedralNumber(n)); return 0; } // This code is contributed by kothavvsaakash.
Java
// 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.
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 Code n = 6 print(centeredTetrahedralNumber(n)) # This code is contributed by ajit
C#
// 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.
PHP
<?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. ?>
Javascript
<script> // Javascript 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 // Given Number var n = 6; document.write(centeredTetrahedralNumber(n)); // This code is contributed by Kirti </script>
Producción :
195
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)