# Heptadecagonal number

Given a number n, the task is to find the nth heptadecagonal number .

A heptadecagonal number is class of figurate number. It has seventeen sided polygon called heptadecagon. The n-th heptadecagonal number count’s the seventeen number of dots and all others dots are surrounding with a common sharing corner and make a pattern.

**Examples:**

Input : 5

Output :155Input :9

Output :549

Formula to calculate nth heptadecagonal number:

## C++

`// C++ program to find Nth ` `// heptadecagonal number ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to calculate heptadecagonal ` `// number ` `int` `heptadecagonalNum(` `long` `int` `n) ` `{ ` ` ` `return` `((15 * n * n) - 13 * n) / 2; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `long` `int` `n = 3; ` ` ` `cout << n << ` `"th Heptadecagonal number : "` `; ` ` ` `cout << heptadecagonalNum(n); ` ` ` `cout << endl; ` ` ` `n = 8; ` ` ` `cout << n << ` `"th Heptadecagonal number : "` `; ` ` ` `cout << heptadecagonalNum(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find Nth heptadecagonal number ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to calculate heptadecagonal ` ` ` `// number ` ` ` `static` `long` `heptadecagonalNum(` `long` `n) ` ` ` `{ ` ` ` `return` `((` `15` `* n * n) - ` `13` `* n) / ` `2` `; ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `long` `n = ` `3` `; ` ` ` `System.out.print( n + ` `"th Heptadecagonal"` ` ` `+ ` `" number : "` `); ` ` ` `System.out.println( heptadecagonalNum(n)); ` ` ` ` ` `n = ` `8` `; ` ` ` `System.out.print( n + ` `"th Heptadecagonal"` ` ` `+ ` `" number : "` `); ` ` ` `System.out.print( heptadecagonalNum(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67. ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find Nth ` `# heptadecagonal number ` ` ` `# Function to calculate ` `# heptadecagonal number ` `def` `heptadecagonalNum(n): ` ` ` ` ` `# Formula to calculate nth ` ` ` `# heptadecagonal number ` ` ` `return` `((` `15` `*` `n ` `*` `n) ` `-` `13` `*` `n) ` `/` `/` `2` ` ` ` ` `# Driver Code ` `n ` `=` `3` `print` `(` `"%sth Heptadecagonal number : "` `%` `n, ` ` ` `heptadecagonalNum(n)) ` `n ` `=` `8` `print` `(` `"%sth Heptadecagonal number: "` `%` `n, ` ` ` `heptadecagonalNum(n)) ` ` ` ` ` `# This code is contributed by ajit ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find Nth ` `// heptadecagonal number ` `using` `System; ` `class` `GFG { ` ` ` ` ` `// Function to calculate ` ` ` `// heptadecagonal number ` ` ` `static` `long` `heptadecagonalNum(` `long` `n) ` ` ` `{ ` ` ` `return` `((15 * n * n) - ` ` ` `13 * n) / 2; ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `long` `n = 3; ` ` ` `Console.Write( n + ` `"th Heptadecagonal"` ` ` `+ ` `" number : "` `); ` ` ` `Console.WriteLine( heptadecagonalNum(n)); ` ` ` ` ` `n = 8; ` ` ` `Console.Write( n + ` `"th Heptadecagonal"` ` ` `+ ` `" number : "` `); ` ` ` `Console.WriteLine( heptadecagonalNum(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find Nth ` `// heptadecagonal number ` ` ` `// Function to calculate heptadecagonal ` `// number ` `function` `heptadecagonalNum( ` `$n` `) ` `{ ` ` ` `return` `((15 * ` `$n` `* ` `$n` `) - ` ` ` `13 * ` `$n` `) / 2; ` `} ` ` ` ` ` `// Driver Code ` ` ` `$n` `= 3; ` ` ` `echo` `$n` `, ` `"th Heptadecagonal number : "` `; ` ` ` `echo` `heptadecagonalNum(` `$n` `); ` ` ` `echo` `"\n"` `; ` ` ` `$n` `= 8; ` ` ` `echo` `$n` `, ` `"th Heptadecagonal number : "` `; ` ` ` `echo` `heptadecagonalNum(` `$n` `); ` ` ` `// This code is contributed by anuj_67. ` `?> ` |

*chevron_right*

*filter_none*

**Output**

3th Heptadecagonal number : 48 8th Heptadecagonal number : 428

Reference: https://en.wikipedia.org/wiki/Polygonal_number

## Recommended Posts:

- Find minimum number to be divided to make a number a perfect square
- Count number of triplets with product equal to given number with duplicates allowed
- Print a number strictly less than a given number such that all its digits are distinct.
- Check if a number is divisible by all prime divisors of another number
- Find the smallest number whose digits multiply to a given number n
- Represent a number as a sum of maximum possible number of Prime Numbers
- Find maximum number that can be formed using digits of a given number
- Build Lowest Number by Removing n digits from a given number
- Find count of digits in a number that divide the number
- Count number of digits after decimal on dividing a number
- Find the largest good number in the divisors of given number N
- Querying maximum number of divisors that a number in a given range has
- Number of digits to be removed to make a number divisible by 3
- Count Number of animals in a zoo from given number of head and legs
- Minimum number of given powers of 2 required to represent a number

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.