8
Most of us are probably familiar with the concept of triangular and square numbers. However, there are also pentagonal numbers, hexagonal numbers, septagonal numbers, octagonal numbers, etc. The Nth Nagonal number is defined as the Nth number of the sequence formed with a polygon of N sides. Obviously, N >= 3, as there are no 2 or 1 sided closed shapes. The first few Nth Ngonal numbers are 0, 1, 2, 6, 16, 35, 66, 112, 176, 261, 370, 506, 672, 871.... This is sequence A060354 in the OEIS.
Your Task:
Write a program or function that, when given an integer n as input, outputs/returns the Nth Nagonal number.
Input:
An integer N between 3 and 10^6.
Output:
The Nth Nagonal number where N is the input.
Test Case:
25 -> 6925
35 -> 19670
40 -> 29680
Scoring:
This is code-golf, lowest score in bytes wins!
Related – Digital Trauma – 2017-10-11T17:55:03.067
It would not hurt to add a direct precise definition. – Wlod AA – 2017-10-12T19:11:20.883