Dado un número n, la tarea es encontrar el n-ésimo número tetradecagonal. Un número tetradecágono es un polígono de 14 lados llamado tetracaidecágono o tetradecágono y pertenece al número figurativo. El enésimo número tetradecagonal está punteado con algunos puntos y crea una serie de patrones. Tienen un punto de esquina común para compartir y salpican sus espacios entre sí. Los puntos continúan con el bucle anidado enésimo.
Ejemplos:
Entrada: 5
Salida: 125Entrada: 7
Salida: 259
Fórmula para el enésimo número tetradecagonal: –
C++
// Program to find nth // Tetradecagonal number #include <bits/stdc++.h> using namespace std; // Function to find // Tetradecagonal number int tetradecagonal_num(int n) { // Formula to calculate nth // tetradecagonal number= return (12 * n * n - 10 * n) / 2; } // Driver Code int main() { int n = 2; cout << n << " th Tetradecagonal number: "; cout << tetradecagonal_num(n); cout << endl; n = 6; cout << n << " th Tetradecagonal number: "; cout << tetradecagonal_num(n); return 0; }
C
// C Program to find nth // Tetradecagonal number #include <stdio.h> // Function to find // Tetradecagonal number int tetradecagonal_num(int n) { // Formula to calculate nth // tetradecagonal number= return (12 * n * n - 10 * n) / 2; } // Driver Code int main() { int n = 2; printf("%dth Tetradecagonal number: ",n); printf("%d\n",tetradecagonal_num(n)); n = 6; printf("%dth Tetradecagonal number: ",n); printf("%d\n",tetradecagonal_num(n)); return 0; } // This code is contributed by kothavvsaakash.
Java
// Java Program to find nth // Tetradecagonal number import java.io.*; class GFG { // Function to find // Tetradecagonal number static int tetradecagonal_num(int n) { // Formula to calculate nth // tetradecagonal number= return (12 * n * n - 10 * n) / 2; } // Driver Code public static void main (String[] args) { int n = 2; System.out.print(n + " th Tetradecagonal" + " number: "); System.out.println(tetradecagonal_num(n)); n = 6; System.out.print(n + " th Tetradecagonal" + " number: "); System.out.print(tetradecagonal_num(n)); } } // This code is code is // contributed by m_kit
Python3
# Program to find nth # Tetradecagonal number # Tetradecagonal number # number function def tetradecagonal_num(n) : # Formula to calculate # nth Tetradecagonal # number return it # into main function. return (12 * n * n - 10 * n) // 2 # Driver Code if __name__ == '__main__' : n = 2 print(n,"th Tetradecagonal " + "number : " , tetradecagonal_num(n)) n = 6 print(n,"th Tetradecagonal " + "number : " , tetradecagonal_num(n)) # This code is contributed ajit
C#
// C# Program to find nth // Tetradecagonal number using System; class GFG { // Function to find // Tetradecagonal number static int tetradecagonal_num(int n) { // Formula to calculate nth // tetradecagonal number return (12 * n * n - 10 * n) / 2; } // Driver Code static public void Main () { int n = 2; Console.Write(n + "th Tetradecagonal" + " number: "); Console.WriteLine(tetradecagonal_num(n)); n = 6; Console.Write(n + "th Tetradecagonal" + " number: "); Console.WriteLine(tetradecagonal_num(n)); } } // This code is contributed by ajit
PHP
<?php // Program to find nth // Tetradecagonal number // Function to find // Tetradecagonal number function tetradecagonal_num($n) { // Formula to calculate nth // tetradecagonal number= return (12 * $n * $n - 10 * $n) / 2; } // Driver Code $n = 2; echo $n , " th Tetradecagonal number: "; echo tetradecagonal_num($n), "\n"; $n = 6; echo $n ," th Tetradecagonal number: "; echo tetradecagonal_num($n); // This code is contributed by aj_36 ?>
Javascript
<script> // Javascript Program to find nth Tetradecagonal number // Function to find // Tetradecagonal number function tetradecagonal_num(n) { // Formula to calculate nth // tetradecagonal number return (12 * n * n - 10 * n) / 2; } let n = 2; document.write(n + "th Tetradecagonal number: "); document.write(tetradecagonal_num(n) + "</br>"); n = 6; document.write(n + "th Tetradecagonal number: "); document.write(tetradecagonal_num(n)); // This code is contributed by suresh07. </script>
Producción :
2 th Tetradecagonal number: 14 6 th Tetradecagonal number: 186
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Referencia:
https://en.wikipedia.org/wiki/Polygonal_number