Skip to content
Related Articles

# Find the sum of the first Nth Centered Tridecagonal Numbers

• Last Updated : 18 Mar, 2021

Given a number N, the task is to find the sum of first N Centered tridecagonal number.

A Centered tridecagonal number represents a dot at the center and other dots surrounding the center dot in the successive tridecagonal(13 sided polygon) layer. The first few Centered tridecagonal numbers are 1, 14, 40, 79 …

Examples:

Input: N = 3
Output: 55
Explanation:
1, 14 and 40 are the first three Centered tridecagonal number.
1 + 14 + 40 = 55.
Input: N = 5
Output: 265

Approach:

1. Initially, we need to create a function which will help us to calculate the Nth Centered tridecagonal number.
2. Now, Run a loop starting from 1 to N, and find the Centered tridecagonal numbers in this range.
3. Add all the above calculated Centered tridecagonal numbers.
4. Finally, display the sum of the first N Centered tridecagonal numbers.

Below is the implementation of the above approach:

## C++

 // C++ program to find the sum of// the first Nth centered// tridecagonal number#includeusing namespace std; // Function to calculate the// N-th centered tridecagonal// numberint Centered_tridecagonal_num(int n){    // Formula to calculate    // Nth centered tridecagonal    // number & return it    return (13 * n * (n - 1) + 2) / 2;}     // Function to find the sum// of the first N centered// tridecagonal numbersint sum_Centered_tridecagonal_num(int n){    // Variable to store    // the sum    int summ = 0;             // Loop to iterate and find the    // sum of first N centered    // tridecagonal numbers    for(int i = 1; i <= n; i++)    {        summ += Centered_tridecagonal_num(i);    }    return summ ;} // Driver codeint main(){    int n = 5;         cout << sum_Centered_tridecagonal_num(n)         << endl;    return 0;} // This code is contributed by rutvik_56

## Java

 // Java program to find the sum of// the first Nth centered// tridecagonal numberclass GFG{     // Function to calculate the// N-th centered tridecagonal// numberpublic static int Centered_tridecagonal_num(int n){         // Formula to calculate    // Nth centered tridecagonal    // number & return it    return (13 * n * (n - 1) + 2) / 2;}     // Function to find the sum// of the first N centered// tridecagonal numberspublic static int sum_Centered_tridecagonal_num(int n){         // Variable to store    // the sum    int summ = 0;             // Loop to iterate and find the    // sum of first N centered    // tridecagonal numbers    for(int i = 1; i <= n; i++)    {       summ += Centered_tridecagonal_num(i);    }    return summ ;} // Driver code   public static void main(String[] args){    int n = 5;         System.out.println(sum_Centered_tridecagonal_num(n));}} // This code is contributed by divyeshrabadiya07

## Python3

 # Program to find the sum of# the first Nth # Centered_tridecagonal number # Function to calculate the# N-th Centered tridecagonal# numberdef Centered_tridecagonal_num(n):     # Formula to calculate     # Nth Centered tridecagonal    # number & return it    return (13 * n *           (n - 1) + 2) // 2        # Function to find the sum# of the first N# Centered tridecagonal# numbersdef sum_Centered_tridecagonal_num(n) :         # Variable to store    # the sum    summ = 0         # Loop to iterate and find the    # sum of first N Centered    # tridecagonal numbers    for i in range(1, n + 1):                  summ += Centered_tridecagonal_num(i)         return summ   # Driver Codeif __name__ == '__main__' :               n = 5     print(sum_Centered_tridecagonal_num(n))

## C#

 // C# program to find the sum of// the first Nth centered// tridecagonal numberusing System; class GFG{     // Function to calculate the// N-th centered tridecagonal// numberpublic static int Centered_tridecagonal_num(int n){         // Formula to calculate    // Nth centered tridecagonal    // number & return it    return (13 * n * (n - 1) + 2) / 2;}     // Function to find the sum// of the first N centered// tridecagonal numberspublic static int sum_Centered_tridecagonal_num(int n){         // Variable to store    // the sum    int summ = 0;             // Loop to iterate and find the    // sum of first N centered    // tridecagonal numbers    for(int i = 1; i <= n; i++)    {       summ += Centered_tridecagonal_num(i);    }    return summ;} // Driver codepublic static void Main(){    int n = 5;         Console.WriteLine(sum_Centered_tridecagonal_num(n));}} // This code is contributed by Code_Mech

## Javascript


Output:
265

Time complexity: O(N).

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up