número heptadecagonal

Dado un número n, la tarea es encontrar el n-ésimo número heptadecagonal. 
Un número heptadecagonal es una clase de números figurados. Tiene un polígono de diecisiete lados llamado heptadecágono. El n-ésimo número heptadecagonal cuenta el número diecisiete de puntos y todos los demás puntos están rodeados por una esquina compartida común y forman un patrón.
 

Ejemplos: 

Entrada: 5 
Salida: 155
Entrada: 9 
Salida: 549 

Heptadecagonal number

Fórmula para calcular el n-ésimo número heptadecagonal: 
 

\begin{math}  Hp_{n}=(15n^2-13n)/2 \end{math}

C++

// C++ program to find Nth
// heptadecagonal number
#include <iostream>
using namespace std;
 
// Function to calculate heptadecagonal
// number
int heptadecagonalNum(long int n)
{
    return ((15 * n * n) - 13 * n) / 2;
}
 
// Driver Code
int main()
{
    long int n = 3;
    cout << n << "th Heptadecagonal number : ";
    cout << heptadecagonalNum(n);
    cout << endl;
    n = 8;
    cout << n << "th Heptadecagonal number : ";
    cout << heptadecagonalNum(n);
 
    return 0;
}

C

// C program to find Nth
// heptadecagonal number
#include <stdio.h>
 
// Function to calculate heptadecagonal
// number
int heptadecagonalNum(long int n)
{
    return ((15 * n * n) - 13 * n) / 2;
}
 
// Driver Code
int main()
{
    long int n = 3;
    printf("%ldth Heptadecagonal number : ",n);
    printf("%d\n",heptadecagonalNum(n));
 
    n = 8;
    printf("%ldth Heptadecagonal number : ",n);
    printf("%d\n",heptadecagonalNum(n));
 
    return 0;
}
 
// This code is contributed by kothavvsaakash

Java

// Java program to find Nth heptadecagonal number
import java.io.*;
 
class GFG {
     
    // Function to calculate heptadecagonal
    // number
    static long heptadecagonalNum(long n)
    {
        return ((15 * n * n) - 13 * n) / 2;
    }
     
    // Driver Code
    public static void main (String[] args)
    {
        long n = 3;
        System.out.print( n + "th Heptadecagonal"
                                 + " number : ");
        System.out.println( heptadecagonalNum(n));
         
        n = 8;
        System.out.print( n + "th Heptadecagonal"
                                 + " number : ");
        System.out.print( heptadecagonalNum(n));
    }
}
 
// This code is contributed by anuj_67.

Python3

# Python program to find Nth
# heptadecagonal number
 
# Function to calculate
# heptadecagonal number
def heptadecagonalNum(n):
 
    # Formula to calculate nth
    # heptadecagonal number
    return ((15 * n * n) - 13 * n) // 2
 
 
# Driver Code
n = 3
print("%sth Heptadecagonal number : " %n,
                    heptadecagonalNum(n))
n = 8
print("%sth Heptadecagonal number: " %n,
                    heptadecagonalNum(n))
                     
                     
# This code is contributed by ajit                

C#

// C# program to find Nth
// heptadecagonal number
using System;
class GFG {
     
    // Function to calculate
    // heptadecagonal number
    static long heptadecagonalNum(long n)
    {
        return ((15 * n * n) -
                  13 * n) / 2;
    }
     
    // Driver Code
    public static void Main ()
    {
        long n = 3;
        Console.Write( n + "th Heptadecagonal"
                                + " number : ");
        Console.WriteLine( heptadecagonalNum(n));
         
        n = 8;
        Console.Write( n + "th Heptadecagonal"
                                + " number : ");
        Console.WriteLine( heptadecagonalNum(n));
    }
}
 
// This code is contributed by anuj_67.

PHP

<?php
// PHP program to find Nth
// heptadecagonal number
 
// Function to calculate heptadecagonal
// number
function heptadecagonalNum( $n)
{
    return ((15 * $n * $n) -
               13 * $n) / 2;
}
 
    // Driver Code
    $n = 3;
    echo $n , "th Heptadecagonal number : ";
    echo heptadecagonalNum($n);
    echo "\n";
    $n = 8;
    echo $n , "th Heptadecagonal number : ";
    echo heptadecagonalNum($n);
 
// This code is contributed by anuj_67.
?>

Javascript

<script>
    // Javascript program to find Nth heptadecagonal number
     
    // Function to calculate
    // heptadecagonal number
    function heptadecagonalNum(n)
    {
        return ((15 * n * n) - 13 * n) / 2;
    }
     
    let n = 3;
    document.write( n + "th Heptadecagonal" + " number : ");
    document.write( heptadecagonalNum(n) + "</br>");
 
    n = 8;
    document.write( n + "th Heptadecagonal" + " number : ");
    document.write( heptadecagonalNum(n));
     
</script>

Producción 
 

3th Heptadecagonal number : 48
8th Heptadecagonal number : 428

Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por jit_t y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *