Find C
Time limit1sMemory limit512 MB
Given lattice points A and B, list K lattice points C such that both segments AC and BC are primitive and triangle ABC contains no other lattice point.
- Level
Hard8 of 10
- Topics
- Number theory, Geometry, Math, Brute force
- Solved
- No attempts yet
Problem
Two friends stand at and , two distinct lattice points in the plane. To fit both of them in one photo you pick a lattice point that satisfies all of the following.
- differs from and from .
- Segment contains no lattice point other than its two endpoints.
- Segment contains no lattice point other than its two endpoints.
- Triangle has area greater than , so does not lie on the line through and .
- No lattice point lies strictly inside triangle .
A point whose coordinate and coordinate are both integers is a lattice point.
Nobody takes a single snap, so for the given and you need such points . Infinitely many points satisfy the conditions, so the output section fixes which of them you print.
Input
The first line contains the number of test cases . ()
Each of the next lines contains five integers , , , , . The two points and are distinct. (, , the sum of all is at most )
Output
For each test case print lines, each holding the coordinates of one point in the format " ". A test case with prints nothing.
Choose the points this way. Among the lattice points that satisfy every condition above, keep only those with
and
Print of the kept points in increasing order of , starting from the smallest.
Infinitely many points remain, so of them always exist, and the kept points have pairwise different values of , so the output is unique. Every coordinate chosen by this rule has absolute value at most .