Skinny Polygon
Time limit3sMemory limit512 MB
For each pair (xbb, ybb), output four vertices of the prescribed skinny polygon: Q1 built from the modular inverse of ybb/g mod xbb/g when 2g <= p+q, otherwise Q2.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Geometry, Implementation
- Solved
- No attempts yet
Problem
Two integers and are given. Call a polygon skinny when it satisfies all of the following conditions.
- It has 3 or 4 vertices.
- Two consecutive edges share only their common endpoint, and two edges that are not consecutive share no point at all.
- Both coordinates of every vertex are integers.
- Every vertex satisfies and .
- At least one vertex has -coordinate , at least one has -coordinate , at least one has -coordinate , and at least one has -coordinate .
- Its area is at most .
A skinny polygon does not have to be convex. Several skinny polygons exist for one pair , so this problem asks for one of them, fixed as follows.
Let , and . Define two quadrilaterals.
- : the integer with and is unique. Using that and , the vertices of in order are , , , . The area of is .
- : the vertices of in order are , , , . The area of is .
Both and are skinny. Print when , and otherwise. The rule prints the one with the smaller area, and when the two areas are equal.
Input
The first line contains the number of test cases (). Each of the next lines holds one test case. A line consists of two integers and (, ).
Output
For each test case print the answer in the following format.
4
x1 y1
x2 y2
x3 y3
x4 y4
The first line is the number of vertices, which is always . The next four lines give the vertices in the order fixed in the statement, one vertex per line, with the two coordinates separated by a single space.