Dado un número n, encuentra el n-ésimo Número Pentadecagonal Centrado.
Un número pentadecagonal centrado representa un punto en el centro y otros puntos que lo rodean en sucesivas capas pentadecagonales (polígono de 15 lados).
Ejemplos:
Input : 2 Output : 16 Input : 8 Output : 421
n-ésimo término del número pentadecagonal centrado: –
A continuación se muestra la implementación básica de la idea anterior.
C++
// C++ Program to find // nth centered // pentadecagonal number #include <bits/stdc++.h> using namespace std; // centered pentadecagonal function int center_pentadecagonal_num(long int n) { // Formula to calculate nth // centered pentadecagonal number return (15 * n * n - 15 * n + 2) / 2; } // Driver Code int main() { long int n = 3; cout << n << "th number : " << center_pentadecagonal_num(n); cout << endl; n = 10; cout << n << "th number : " << center_pentadecagonal_num(n); return 0; }
C
// C Program to find // nth centered // pentadecagonal number #include <stdio.h> // centered pentadecagonal function int center_pentadecagonal_num(long int n) { // Formula to calculate nth // centered pentadecagonal number return (15 * n * n - 15 * n + 2) / 2; } // Driver Code int main() { long int n = 3; printf("%ldth number : %d\n",n,center_pentadecagonal_num(n)); n = 10; printf("%ldth number : %d\n",n,center_pentadecagonal_num(n)); return 0; } // This code is contributed by kothavvsaakash.
Java
// Java Program to find nth centered // pentadecagonal number import java.io.*; class GFG { // centered pentadecagonal function static long center_pentadecagonal_num(long n) { // Formula to calculate nth // centered pentadecagonal number return (15 * n * n - 15 * n + 2) / 2; } // Driver Code public static void main (String[] args) { long n = 3; System.out.print(n + "th number : "); System.out.println( center_pentadecagonal_num(n)); n = 10; System.out.print( n + "th number : "); System.out.println( center_pentadecagonal_num(n)); } } // This code is contributed by ajit.
Python3
# Program to find nth #centered pentadecagonal number def center_pentadecagonal_num(n) : # Formula to calculate nth # centered pentadecagonal number return (15 * n * n - 15 * n + 2) // 2 # Driver Code if __name__ == '__main__' : n = 3 print(n,"rd number : ", center_pentadecagonal_num(n)) n = 10 print(n,"th number : ", center_pentadecagonal_num(n)) # This code is contributed by m_kit
C#
// C# Program to find // nth centered // pentadecagonal number using System; class GFG { // centered // pentadecagonal function static long center_pentadecagonal_num(long n) { // Formula to calculate // nth centered // pentadecagonal number return (15 * n * n - 15 * n + 2) / 2; } // Driver Code static public void Main () { long n = 3; Console.Write(n + "th number : "); Console.WriteLine( center_pentadecagonal_num(n)); n = 10; Console.Write( n + "th number : "); Console.WriteLine( center_pentadecagonal_num(n)); } } // This code is contributed by ajit.
PHP
<?php // PHP Program to find // nth centered // pentadecagonal number // centered pentadecagonal function function center_pentadecagonal_num($n) { // Formula to calculate nth // centered pentadecagonal number return (15 * $n * $n - 15 * $n + 2) / 2; } // Driver Code $n = 3; echo $n , "th number : ", center_pentadecagonal_num($n); echo "\n"; $n = 10; echo $n , "th number : ", center_pentadecagonal_num($n); // This code is contributed by m_kit ?>
Javascript
<script> // Javascript program to find nth centered // pentadecagonal number // centered pentadecagonal function function center_pentadecagonal_num(n) { // Formula to calculate nth // centered pentadecagonal number return (15 * n * n - 15 * n + 2) / 2; } // Driver Code var n = 3; document.write(n + "th number : "); document.write(center_pentadecagonal_num(n) + "<br>"); n = 10; document.write( n + "th number : "); document.write(center_pentadecagonal_num(n)); // This code is contributed by Kirti </script>
Producción :
3th number : 46 10th number : 676
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)