Un número nonagonal es un número figurado que extiende el concepto de números triangulares y cuadrados al nonágono. Específicamente, los números nonagonales n cuentan la cantidad de puntos en un patrón de n nonágonos anidados (polígonos de 9 lados), todos compartiendo una esquina común, donde el nonágono i en el patrón tiene lados hechos de puntos i espaciados una unidad entre sí .
Ejemplos:
Input : n = 10 n (7n - 5) / 2 10 * (7 * 10 - 5) / 2 10 * 65 / 2 = 325 Output :325 Input : 15 Output :750
El enésimo número no ogonal viene dado por la fórmula: n ( 7n – 5) / 2 .
C++
// CPP Program to find // nth nonagonal number. #include <bits/stdc++.h> using namespace std; // Function to find nth // nonagonal number. int Nonagonal(int n) { // Formula to find nth // nonagonal number. return n * (7 * n - 5) / 2; } // Driver function. int main() { int n = 10; cout << Nonagonal(n); return 0; }
Java
// Java Program to find // nth nonagonal number. import java.io.*; class GFG { // Function to find nth // nonagonal number. static int Nonagonal(int n) { // Formula to find nth // nonagonal number. return n * (7 * n - 5) / 2; } // Driver function. public static void main(String args[]) { int n = 10; System.out.println(Nonagonal(n)); } } // This code is contributed by Nikita Tiwari.
Python3
# Python 3 Program to find # nth nonagonal number. # Function to find nth # nonagonal number. def Nonagonal(n): # Formula to find nth # nonagonal number. return int(n * (7 * n - 5) / 2) n = 10 print(Nonagonal(n)) # This code is contributed by # Smitha Dinesh Semwal
C#
// C# Program to find // nth nonagonal number. using System; class GFG { // Function to find nth // nonagonal number. static int Nonagonal(int n) { // Formula to find nth // nonagonal number. return n * (7 * n - 5) / 2; } // Driver function. public static void Main() { int n = 10; Console.Write(Nonagonal(n)); } } // This code is contributed by vt_m.
PHP
<?php // PHP Program to find // nth nonagonal number. // Function to find nth // nonagonal number. function Nonagonal($n) { // Formula to find nth // nonagonal number. return $n * (7 * $n - 5) / 2; } // Driver Code $n = 10; echo Nonagonal($n); // This code is contributed by vt_m. ?>
Javascript
<script> // Javascript Program to find // nth nonagonal number. // Function to find nth // nonagonal number. function Nonagonal(n) { // Formula to find nth // nonagonal number. return parseInt(n * (7 * n - 5) / 2); } // Driver function. let n = 10; document.write(Nonagonal(n)); // This code is contributed by souravmahato348. </script>
Producción :
325
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)
Dado un número n, encuentre series de números no ogonales hasta n términos .
C++
// CPP Program find first // n nonagonal number. #include <bits/stdc++.h> using namespace std; // Function to find nonagonal // number series. int Nonagonal(int n) { for (int i = 1; i <= n; i++) { cout << i * (7 * i - 5) / 2; cout << " "; } } // Driver Code int main() { int n = 10; Nonagonal(n); return 0; }
Java
// Java Program find first // n nonagonal number. import java.io.*; class GFG { // Function to find nonagonal // number series. static void Nonagonal(int n) { for (int i = 1; i <= n; i++) { System.out.print(i * (7 * i - 5) / 2); System.out.print(" "); } } // Driver Code public static void main(String args[]) { int n = 10; Nonagonal(n); } } // This code is contributed // by Nikita Tiwari.
Python3
# Python 3 Program find first # n nonagonal number. # Function to find nonagonal # number series. def Nonagonal(n): for i in range(1, n+1): print(int(i * (7 * i - 5) / 2),end=" ") # driver Function n = 10 Nonagonal(n) # This code is contributed by # Smitha Dinesh Semwal
C#
// C# Program find first // n nonagonal number. using System; class GFG { // Function to find nonagonal // number series. static void Nonagonal(int n) { for (int i = 1; i <= n; i++) { Console.Write(i * (7 * i - 5) / 2); Console.Write(" "); } } // Driver Code public static void Main() { int n = 10; Nonagonal(n); } } // This code is contributed by vt_m.
PHP
<?php // PHP Program find first // n nonagonal number. // Function to find nonagonal // number series. function Nonagonal($n) { for ( $i = 1; $i <= $n; $i++) { echo $i * (7 * $i - 5) / 2; echo " "; } } // Driver Code $n = 10; Nonagonal($n); // This code is contributed by ajit ?>
Javascript
<script> // Javascript Program find first // n nonagonal number. // Function to find nonagonal // number series. function Nonagonal(n) { for (let i = 1; i <= n; i++) { document.write(parseInt(i * (7 * i - 5) / 2) + " "); } } // Driver Code let n = 10; Nonagonal(n); </script>
Producción :
1 9 24 46 75 111 154 204 261 325
Complejidad de tiempo: O(n)
Espacio Auxiliar: O(1)
Referencia: https://en.wikipedia.org/wiki/Nonagonal_number
Publicación traducida automáticamente
Artículo escrito por Shashank12 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA