#P9085. Counting Special Convex Polygons
Counting Special Convex Polygons
Counting Special Convex Polygons
Given a grid of points with integer coordinates, count the number of distinct convex polygons that satisfy all of the following conditions, and output the result modulo :
- The th vertex of the polygon is where and , .
- For any edge of the polygon (excluding its endpoints), the edge does not pass through any lattice point (i.e. a point where both coordinates are integers). Equivalently, if an edge connects and then $$\gcd(|x_2-x_1|,|y_2-y_1|)=1.$$
- The length of every edge is an integer and does not exceed . That is, if an edge from to has length $$\sqrt{(x_2-x_1)^2+(y_2-y_1)^2},$$ then there exists an integer with $$d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\quad \text{and}\quad d\le K.$$
- The polygon is convex and non-degenerate; in particular, it must have at least three vertices, no three vertices are collinear, it does not self-intersect, and every internal angle is strictly less than .
- Two polygons are considered different if they differ in at least one vertex.
The input consists of three integers , , and . Note that due to the huge number of polygons that can meet the above conditions, you only need to output the total count modulo .
inputFormat
The input consists of a single line containing three positive integers , , and , separated by spaces.
outputFormat
Output a single integer: the number of distinct convex polygons satisfying the conditions, taken modulo .
sample
2 2 3
1