Número icosidigonal

Dado un número n, la tarea es encontrar el n-ésimo número Icosidigonal (Isdn). 
El polígono tiene muchos gons, depende de su serie de números gonales. En matemáticas, hay una serie de números gonales y el número icosidigonal es uno de ellos y estos números tienen un polígono de 22 lados (icosidigón). Un número icosidigonal pertenece a la clase de número figurativo. Tienen puntos de puntos comunes y otro patrón de puntos está dispuesto en un patrón de icosidigón anidado enésimo.
Ejemplos: 
 

Entrada: 2 
Salida: 22
Entrada: 6 
Salida: 306 
 

icosidigonal number22

Fórmula para el enésimo número icosidigonal: 
 

\begin{math}  Isd_{n}=((20n^2)-18n)/2 \end{math}

C++

// C++ program to find nth Icosidigonal
// number
#include <bits/stdc++.h>
using namespace std;
 
// Function to calculate Icosidigonal number
int icosidigonal_num(long int n)
{
    // Formula for finding
    // nth Icosidigonal number
    return (20 * n * n - 18 * n) / 2;
}
 
// Driver function
int main()
{
    long int n = 4;
    cout << n << "th Icosidigonal number :" << icosidigonal_num(n);
    cout << endl;
    n = 8;
    cout << n << "th Icosidigonal number:" << icosidigonal_num(n);
    return 0;
}

C

// C program to find nth Icosidigonal
// number
#include <stdio.h>
 
// Function to calculate Icosidigonal number
int icosidigonal_num(long int n)
{
   
    // Formula for finding
    // nth Icosidigonal number
    return (20 * n * n - 18 * n) / 2;
}
 
// Driver function
int main()
{
    long int n = 4;
    printf("%ldth Icosidigonal number : %d\n",n,icosidigonal_num(n));
 
    n = 8;
    printf("%ldth Icosidigonal number : %d\n",n,icosidigonal_num(n));
    return 0;
}
 
// This code is contributed by kothavvsaakash.

Java

// Java program to find nth
// Icosidigonal number
import java.io.*;
 
class GFG
{
     
    // Function to calculate
    // Icosidigonal number
    static int icosidigonal_num(int n)
    {
         
    // Formula for finding
    // nth Icosidigonal number
     
    return (20 * n * n - 18 * n) / 2;
    }
 
// Driver Code
public static void main (String[] args)
{
 
    int n = 4;
    System.out.print (n + "th Icosidigonal number :");
    System.out.println (icosidigonal_num(n));
 
    n = 8;
    System.out.print (n + "th Icosidigonal number :");
    System.out.println (icosidigonal_num(n));
}
}
 
// This code is contributed by ajit

Python 3

# python 3 program to find
# nth Icosidigonal number
 
# Function to calculate
# Icosidigonal number
def icosidigonal_num(n) :
     
    # Formula for finding
    # nth Icosidigonal number
    return (20 * n * n -
            18 * n) // 2
 
# Driver Code
if __name__ == '__main__' :
         
    n = 4
    print(n,"th Icosidigonal " +
                    "number : ",
            icosidigonal_num(n))
    n = 8
    print(n,"th Icosidigonal " +
                    "number : ",
            icosidigonal_num(n))
     
# This code is contributed m_kit

C#

// C# program to find nth
// Icosidigonal number
using System;
 
class GFG
{
     
    // Function to calculate
    // Icosidigonal number
    static int icosidigonal_num(int n)
    {
         
    // Formula for finding
    // nth Icosidigonal number
    return (20 * n * n -
            18 * n) / 2;
    }
 
// Driver Code
static public void Main ()
{
int n = 4;
Console.Write(n + "th Icosidigonal " +
                          "number :");
Console.WriteLine(icosidigonal_num(n));
 
n = 8;
Console.Write (n + "th Icosidigonal "+
                          "number :");
Console.WriteLine(icosidigonal_num(n));
}
}
 
// This code is contributed by ajit

PHP

<?php
// PHP program to find nth
// Icosidigonal number
 
// Function to calculate
// Icosidigonal number
function icosidigonal_num($n)
{
    // Formula for finding
    // nth Icosidigonal number
    return (20 * $n * $n - 18 * $n) / 2;
}
 
// Driver Code
$n = 4;
echo $n , "th Icosidigonal number : ",
                icosidigonal_num($n);
echo "\n";
$n = 8;
echo $n , "th Icosidigonal number : ",
               icosidigonal_num($n);
     
// This code is contributed by m_kit
?>

Javascript

<script>
 
// JavaScript program to find nth Icosidigonal
// number
 
// Function to calculate Icosidigonal number
function icosidigonal_num(n)
{
    // Formula for finding
    // nth Icosidigonal number
    return parseInt((20 * n * n - 18 * n) / 2);
}
 
// Driver function
let n = 4;
document.write(n + "th Icosidigonal number :" + icosidigonal_num(n));
document.write("<br>");
n = 8;
document.write(n + "th Icosidigonal number :" + icosidigonal_num(n));
 
</script>

Producción : 

4th Icosidigonal number :124
8th Icosidigonal number:568

Complejidad de tiempo: O(1)
Espacio auxiliar: O(1)
Referencia: https://en.wikipedia.org/wiki/Polygonal_number
 

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 *