# Find the sum of the first Nth Icosidigonal Number

Given a number N, the task is to find the sum of the first N Icosidigonal Numbers.

The first few Icosidigonal numbers are 1, 22, 63, 124, 205, 306 …

Examples:

Input: N = 3
Output: 86
Explanation:
1, 22 and 63 are the first three Icosidigonal numbers.

Input: N = 6
Output: 721

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

1. Initially, we need to create a function which will help us to calculate the Nth icosidigonal number.
2. Now, run a loop starting from 1 to N, to find ith icosidigonal numbers.
3. Add all the above calculated icosidigonal numbers.
4. Finally, display the sum of the first N Icosidigonal numbers.

Below is the implementation of the above approach:

## C++

 `// C++ program to find the sum of the ` `// first N icosidigonal numbers ` `#include   ` `using` `namespace` `std;  ` ` `  `// Function to find the  ` `// N-th icosidigonal number  ` `int` `Icosidigonal_num(``int` `n)  ` `{ ` `     `  `    ``// Formula to calculate  ` `    ``// nth icosidigonal number ` `    ``return` `(20 * n * n - 18 * n) / 2; ` `} ` ` `  `// Function to find the sum of the ` `// first N icosidigonal number  ` `int` `sum_Icosidigonal_num(``int` `n) ` `{ ` `     `  `    ``// Variable to store the sum ` `    ``int` `summ = 0; ` `     `  `    ``// Iterating in the range 1 to N ` `    ``for``(``int` `i = 1; i < n + 1; i++) ` `    ``{ ` `         `  `        ``// Finding the sum ` `        ``summ += Icosidigonal_num(i); ` `    ``} ` `    ``return` `summ; ` `} ` ` `  `// Driver code  ` `int` `main()  ` `{  ` `    ``int` `n = 6; ` `     `  `    ``// Display first Nth  ` `    ``// icosidigonal numbers ` `    ``cout << sum_Icosidigonal_num(n); ` `}  ` ` `  `// This code is contributed by coder001 `

## Java

 `// Java program to find the sum of the  ` `// first N icosidigonal numbers  ` `class` `GFG{ ` `     `  `// Function to find the  ` `// N-th icosidigonal number  ` `public` `static` `int` `Icosidigonal_num(``int` `n)  ` `{  ` `         `  `    ``// Formula to calculate  ` `    ``// nth icosidigonal number  ` `    ``return` `(``20` `* n * n - ``18` `* n) / ``2``;  ` `}  ` `     `  `// Function to find the sum of the  ` `// first N icosidigonal number  ` `public` `static` `int` `sum_Icosidigonal_num(``int` `n)  ` `{  ` `         `  `    ``// Variable to store the sum  ` `    ``int` `summ = ``0``;  ` `         `  `    ``// Iterating in the range 1 to N  ` `    ``for``(``int` `i = ``1``; i < n + ``1``; i++)  ` `    ``{  ` ` `  `       ``// Finding the sum  ` `       ``summ += Icosidigonal_num(i);  ` `    ``}  ` `    ``return` `summ;  ` `}  ` ` `  `// Driver code     ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``int` `n = ``6``;  ` `     `  `    ``// Display first Nth  ` `    ``// icosidigonal numbers  ` `    ``System.out.println(sum_Icosidigonal_num(n)); ` `} ` `} ` ` `  `// This code is contributed by divyeshrabadiya07     `

## Python3

 `# Python3 program to find the  ` `# sum of the first N   ` `# Icosidigonal numbers ` ` `  `# Function to find the  ` `# N-th Icosidigonal  ` `# number  ` `def` `Icosidigonal_num(n): ` `  `  `    ``# Formula to calculate   ` `    ``# nth Icosidigonal  ` `    ``# number ` `    ``return` `(``20` `*` `n ``*` `n ``-`  `            ``18` `*` `n) ``/``/` `2` `     `  `   `  `# Function to find the  ` `# sum of the first N ` `# Icosidigonal number  ` `def` `sum_Icosidigonal_num(n) :  ` `     `  `    ``# Variable to store ` `    ``# the sum ` `    ``summ ``=` `0` `     `  `    ``# Iterating in the range  ` `    ``# 1 to N ` `    ``for` `i ``in` `range``(``1``, n ``+` `1``): ` ` `  `        ``summ ``+``=` `Icosidigonal_num(i) ` `     `  `    ``return` `summ ` `   `  `# Driver code  ` `if` `__name__ ``=``=` `'__main__'` `:  ` `           `  `    ``n ``=` `6` `     `  ` `  `    ``print``(sum_Icosidigonal_num(n))  `

## C#

 `// C# program to find the sum of the  ` `// first N icosidigonal numbers  ` `using` `System; ` ` `  `class` `GFG{  ` `         `  `// Function to find the  ` `// N-th icosidigonal number  ` `static` `int` `Icosidigonal_num(``int` `n)  ` `{  ` `             `  `    ``// Formula to calculate  ` `    ``// nth icosidigonal number  ` `    ``return` `(20 * n * n - 18 * n) / 2;  ` `}  ` `         `  `// Function to find the sum of the  ` `// first N icosidigonal number  ` `static` `int` `sum_Icosidigonal_num(``int` `n)  ` `{  ` `             `  `    ``// Variable to store the sum  ` `    ``int` `summ = 0;  ` `             `  `    ``// Iterating in the range 1 to N  ` `    ``for``(``int` `i = 1; i < n + 1; i++)  ` `    ``{  ` `         `  `       ``// Finding the sum  ` `       ``summ += Icosidigonal_num(i);  ` `    ``}  ` `    ``return` `summ;  ` `}  ` `     `  `// Driver code  ` `public` `static` `void` `Main(``string``[] args)  ` `{  ` `    ``int` `n = 6;  ` `         `  `    ``// Display first Nth  ` `    ``// icosidigonal numbers  ` `    ``Console.WriteLine(sum_Icosidigonal_num(n));  ` `}  ` `}  ` ` `  `// This code is contributed by AnkitRai01`

Output:

```721
```

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.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.