# Find the sum of the first Nth Centered Tridecagonal Numbers

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 = 3Output:55Explanation:

1, 14 and 40 are the first three Centered tridecagonal number.

1 + 14 + 40 = 55.Input:N = 5Output:265

**Approach:**

- Initially, we need to create a function which will help us to calculate the N
^{th}Centered tridecagonal number. - Now, Run a loop starting from 1 to N, and find the Centered tridecagonal numbers in this range.
- Add all the above calculated Centered tridecagonal numbers.
- 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` `#include<bits/stdc++.h>` `using` `namespace` `std;` `// Function to calculate the` `// N-th centered tridecagonal` `// number` `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 numbers` `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` `int` `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 number` `class` `GFG{` ` ` `// Function to calculate the` `// N-th centered tridecagonal` `// number` `public` `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 numbers` `public` `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` `# number` `def` `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` `# numbers` `def` `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 Code` `if` `__name__ ` `=` `=` `'__main__'` `:` ` ` ` ` `n ` `=` `5` ` ` `print` `(sum_Centered_tridecagonal_num(n))` |

## C#

`// C# program to find the sum of` `// the first Nth centered` `// tridecagonal number` `using` `System;` `class` `GFG{` ` ` `// Function to calculate the` `// N-th centered tridecagonal` `// number` `public` `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 numbers` `public` `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()` `{` ` ` `int` `n = 5;` ` ` ` ` `Console.WriteLine(sum_Centered_tridecagonal_num(n));` `}` `}` `// This code is contributed by Code_Mech` |

## Javascript

`<script>` ` ` `// Javascript program to find the sum of ` ` ` `// the first Nth centered` ` ` `// tridecagonal number ` ` ` ` ` `// Function to calculate the ` ` ` `// N-th centered tridecagonal ` ` ` `// number ` ` ` `function` `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 numbers ` ` ` `function` `sum_Centered_tridecagonal_num(n)` ` ` `{` ` ` ` ` `// Variable to store ` ` ` `// the sum ` ` ` `let summ = 0;` ` ` `// Loop to iterate and find the ` ` ` `// sum of first N centered ` ` ` `// tridecagonal numbers ` ` ` `for` `(let i = 1; i <= n; i++)` ` ` `{` ` ` `summ += Centered_tridecagonal_num(i); ` ` ` `}` ` ` `return` `summ ;` ` ` `}` ` ` ` ` `let n = 5; ` ` ` `document.write(sum_Centered_tridecagonal_num(n));` ` ` ` ` `// This code is contributed by divyesh072019.` `</script>` |

**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**.