Número tridecagonal centrado

Dado un número n, la tarea es encontrar el n-ésimo Número Tridecagonal Centrado. 
Un número tridecagonal centrado representa un punto en el centro y otros puntos que rodean el punto central 
en la capa tridecagonal sucesiva (polígono de 13 lados).

Ejemplos:  

Entrada: 2 
Salida: 14

Entrada : 9 
Salida : 469 
 

centered tridecagonal number

Fórmula para el número tridecagonal centrado en n: 

CT_{n}= (13n(n-1)+2)/2

C++

// C++ Program to find nth
// centered tridecagonal number
#include <bits/stdc++.h>
using namespace std;
 
// Function to find nth centered
// tridecagonal number
int centeredTridecagonalNum(long int n)
{
    // Formula to calculate nth
    // centered tridecagonal number
    return (13 * n * (n - 1) + 2) / 2;
}
 
// Drivers code
int main()
{
    long int n = 3;
    cout << centeredTridecagonalNum(n);
    cout << endl;
    n = 10;
    cout << centeredTridecagonalNum(n);
 
    return 0;
}

C

// C Program to find nth
// centered tridecagonal number
#include <stdio.h>
 
// Function to find nth centered
// tridecagonal number
int centeredTridecagonalNum(long int n)
{
    // Formula to calculate nth
    // centered tridecagonal number
    return (13 * n * (n - 1) + 2) / 2;
}
 
// Drivers code
int main()
{
    long int n = 3;
    printf("%d\n",centeredTridecagonalNum(n));
     
    n = 10;
    printf("%d\n",centeredTridecagonalNum(n));
 
    return 0;
}
 
// This code is contributed by kothavvsaakash.

Java

// Java Program to find nth
// centered tridecagonal number
import java.io.*;
 
class GFG
{
 
// Function to find nth centered
// tridecagonal number
static long centeredTridecagonalNum(long n)
{
    // Formula to calculate nth
    // centered tridecagonal number
    return (13 * n * (n - 1) + 2) / 2;
}
 
// Driver Code
public static void main (String[] args)
{
    long n = 3;
    System.out.println(centeredTridecagonalNum(n));
    n = 10;
    System.out.println(centeredTridecagonalNum(n));
}
}
 
// This code is contributed by anuj_67.

Python3

# Program to find nth centered
# tridecagonal number
 
# Function to find centered
# tridecagonal number
def centeredTridecagonalNum(n) :
     
    # Formula to calculate nth
    # centered tridecagonal number
    return (13 * n *
           (n - 1) + 2) // 2
 
# Driver Code
if __name__ == '__main__' :
         
    n = 3
    print(centeredTridecagonalNum(n))
    n = 10
    print(centeredTridecagonalNum(n))
                 
# This code is contributed
# by akt_mit

C#

// C# Program to find nth
// centered tridecagonal number
using System;
 
class GFG
{
 
// Function to find nth centered
// tridecagonal number
static long centeredTridecagonalNum(long n)
{
    // Formula to calculate nth
    // centered tridecagonal number
    return (13 * n * (n - 1) + 2) / 2;
}
 
// Driver Code
public static void Main ()
{
    long n = 3;
    Console.WriteLine(centeredTridecagonalNum(n));
    n = 10;
    Console.WriteLine(centeredTridecagonalNum(n));
}
}
 
// This code is contributed by anuj_67.

PHP

<?php
// PHP Program to find nth
// centered tridecagonal number
 
// Function to find nth centered
// tridecagonal number
function centeredTridecagonalNum( $n)
{
    // Formula to calculate nth
    // centered tridecagonal number
    return (13 * $n *
           ($n - 1) + 2) / 2;
}
 
// Driver Code
$n = 3;
echo centeredTridecagonalNum($n);
echo"\n";
 
$n = 10;
echo centeredTridecagonalNum($n);
 
// This code is contributed by anuj_67.
?>

Javascript

<script>
 
// Javascript program to find nth
// centered tridecagonal number
 
// Function to find nth centered
// tridecagonal number
function centeredTridecagonalNum(n)
{
     
    // Formula to calculate nth
    // centered tridecagonal number
    return (13 * n * (n - 1) + 2) / 2;
}
 
// Driver code
var n = 3;
document.write(centeredTridecagonalNum(n) + "<br>");
  
n = 10;
document.write(centeredTridecagonalNum(n));
 
// This code is contributed by Ankita saini
 
</script>
Producción : 

40
586

 

Complejidad Temporal: O(1)
Espacio Auxiliar: O(1)
Referencia: http://oeis.org/wiki/Figurate_numbers
 

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 *