Número dodecaédrico centrado

Dado un número n, encuentre el n-ésimo número dodecaédrico centrado.
Un número dodecaédrico centrado es una clase de número figurativo. Está formado por un punto central, rodeado por sucesivas capas dodecaédricas (poliédricas con 12 superficies planas). 
Los primeros números dodecaédricos centrados (donde n = 0, 1, 2, 3…….) son: 
1, 33, 155, 427, 909, 1661 ……………
Ejemplos: 
 

Input : 5
Output : 1661

Input :1
Output :33

La fórmula matemática para el n-ésimo número dodecaédrico centrado está dada por: 
 

Cd_{n}=(2n+1)(5n^2+5n+1)

A continuación se muestra la implementación básica de la idea anterior:
 

C++

// Program to find nth centered
// dodecahedral number
#include <bits/stdc++.h>
using namespace std;
 
// Function to find
// centered dodecahedral number
int CenteredDodecahedral_num(long int n)
{
    // Formula to calculate nth
    // centered dodecahedral number
    // and return it into main function.
    return (2 * n + 1) * (5 * n * n + 5 * n + 1);
}
// Driver Code
int main()
{
    long int n = 3;
    // print result
    cout << n << "th Centered Dodecahedral number : ";
    cout << CenteredDodecahedral_num(n) << endl;
 
    n = 10;
    // print result
    cout << n << "th Centered Dodecahedral number : ";
    cout << CenteredDodecahedral_num(n);
 
    return 0;
}

C

// C Program to find nth centered
// dodecahedral number
#include <stdio.h>
 
// Function to find
// centered dodecahedral number
int CenteredDodecahedral_num(long int n)
{
    // Formula to calculate nth
    // centered dodecahedral number
    // and return it into main function.
    return (2 * n + 1) * (5 * n * n + 5 * n + 1);
}
 
// Driver Code
int main()
{
    long int n = 3;
   
    // print result
    printf("%ldth Centered Dodecahedral number : %d\n",n,CenteredDodecahedral_num(n));
 
    n = 10;
    // print result
    printf("%ldth Centered Dodecahedral number : %d\n",n,CenteredDodecahedral_num(n));
 
    return 0;
}
 
// This code is contributed by kothavvsaakash.

Java

// Java Program to find nth
// centered dodecahedral number
import java.io.*;
 
class GFG {
 
    // Function to find centered
    // dodecahedral number
    static int CenteredDodecahedral_num(int n)
    {
         
        // Formula to calculate nth
        // centered dodecahedral number
        // and return it into main function.
         
        return (2 * n + 1) *
                     (5 * n * n + 5 * n + 1);
    }
     
    // Driver Code
    public static void main (String[] args)
    {
 
        int n = 3;
         
        // print result
        System.out.print( n + "th Centered "
                + "Dodecahedral number : ");
        System.out.println (
                CenteredDodecahedral_num(n));
 
        n = 10;
         
        // print result
        System.out.print( n + "th Centered "
                + "Dodecahedral number : ");
        System.out.println(
               CenteredDodecahedral_num(n));
    }
}
 
// This code is contributed by m_kit.

Python3

# Program to find nth centered
# dodecahedral number
 
# Function to find centered
# dodecahedral number
def CenteredDodecahedral_num(n) :
     
    # Formula to calculate nth
    # centered dodecahedral number
    return (2 * n + 1) * (5 * n * n + 5 * n + 1)
 
# Driver Code
if __name__ == '__main__' :
         
    n = 3
    print(n,"rd centered dodecahedral number: ",
                CenteredDodecahedral_num(n))
    n = 10
    print(n,"th centered dodecahedral number : ",
                CenteredDodecahedral_num(n))
                 
# This code is contributed by aj_36

C#

// C# Program to find
// nth centered
// dodecahedral number
using System;
 
class GFG
{
     
    // Function to find
    // nth centered
    // dodecahedral number
    static int CenteredDodecahedral_num(int n)
    {
         
        // Formula to calculate
        // nth centered dodecahedral
        // number and return it
        // into main function.
        return (2 * n + 1) *
               (5 * n * n +
                5 * n + 1);
    }
     
    // Driver Code
    static public void Main ()
    {
        int n = 3;
         
        // print result
        Console.Write( n + "th Centered " +
                 "Dodecahedral number : ");
        Console.WriteLine(
                CenteredDodecahedral_num(n));
 
        n = 10;
         
        // print result
        Console.Write( n + "th Centered " +
                 "Dodecahedral number : ");
        Console.WriteLine(
                CenteredDodecahedral_num(n));
    }
}
 
// This code is contributed by ajit

PHP

<?php
// Program to find nth centered
// dodecahedral number
 
// Function to find
// centered dodecahedral number
function CenteredDodecahedral_num($n)
{
    // Formula to calculate nth
    // centered dodecahedral number
    // and return it into main function.
    return (2 * $n + 1) *
           (5 * $n * $n +
            5 * $n + 1);
}
 
// Driver Code
$n = 3;
// print result
echo $n, "th Centered Dodecahedral " .
                          "number : ";
echo CenteredDodecahedral_num($n),"\n";
 
$n = 10;
// print result
echo $n, "th Centered Dodecahedral " .
                          "number : ";
echo CenteredDodecahedral_num($n);
 
// This code is contributed by akt_mit
?>

Javascript

<script>
 
// Javascript Program to find nth
// centered dodecahedral number
 
// Function to find centered
// dodecahedral number
function CenteredDodecahedral_num(n)
{
     
    // Formula to calculate nth
    // centered dodecahedral number
    // and return it into main function.
    return (2 * n + 1) *
           (5 * n * n + 5 * n + 1);
}
     
// Driver code
var n = 3;
         
// print result
document.write(n + "th Centered " +
               "Dodecahedral number : ");
document.write(CenteredDodecahedral_num(n) + "<br>");
 
n = 10;
 
// print result
document.write(n + "th Centered " +
               "Dodecahedral number : ");
document.write(CenteredDodecahedral_num(n));
 
// This code is contributed by Khushboogoyal499
 
</script>

Producción : 
 

3th Centered Dodecahedral number : 427
10th Centered Dodecahedral number : 11571

Complejidad de tiempo: O(1)
Espacio auxiliar: O(1)
Referencias:  
https://en.wikipedia.org/wiki/Centered_dodecahedral_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 *