Back
Close

Diagonals

Statement

 Goal

A diagonal of a polygon is defined as a segment joining any two non-consecutive vertices of the polygon.
How many diagonals are there in a convex polygon with N vertices?
Input
N, the number of vertices
Output
D, the number of diagonals
Constraints
3 ≤ N ≤ 134217728
Example
Input
4
Output
2

Game modes
Fastest, Shortest

Test cases
Square Test
Input
4
Output
2

Triangle Validator
Input
3
Output
0

Triangle Test
Input
3
Output
0

Pentagon Validator
Input
5
Output
5

Tetracontadigon Test
Input
42
Output
819

Hexahectahexacontahexagon Validator
Input
666
Output
220779

Figure this one out yourself Test
Input
134217728
Output
9007199053414400

Figure this one out yourself too Validator
Input
134217727
Output
9007198919196674

Wow many diagonals Test
Input
67108864
Output
2251799713021952

Wow many diagonals but slightly less Validator
Input
67108863
Output
2251799645913090

Solution language

Solution

Stub generator input