Shrinking Inscribed Polygon
Time limit1sMemory limit128 MB
Given arc lengths around an inscribed polygon, find the minimum number of vertices to delete so the remaining vertices form a regular polygon, or report -1.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Array, Prefix sum
- Solved
- No attempts yet
Problem
A polygon is said to be inscribed in a circle when all of its vertices lie on that circle. Given a polygon inscribed in a circle, determine the minimum number of vertices that must be removed so that the remaining polygon becomes a regular polygon. A regular polygon is a polygon in which every side has the same length and every interior angle has the same measure.
To remove a vertex from the polygon, first find its two neighboring vertices and , then connect and with a new edge. Doing so merges the two arcs that had between them into a single arc.
For example, from an inscribed polygon with vertices you can remove a suitable set of vertices to form a regular pentagon.
The polygon always has at least sides.
Input
The input consists of several test cases.
The first line of each test case contains the number of vertices of the inscribed polygon. () The second line contains integers . ()
is the arc length between vertex and vertex , given in clockwise order. Note that an arc is measured along the circle's circumference, not as a chord.
The last line of the input contains a single , which is not processed.
Output
For each test case, print on one line the minimum number of vertices that must be removed to form a regular polygon. If no regular polygon can be formed, print .