Triangle Areas (Large)
Time limit5sMemory limit512 MB
Given N, M and A, print the canonical triangle (0,0), (N,1), (w,h) with area A/2, or IMPOSSIBLE when A exceeds N*M.
- Level
Easy3 of 10
- Topics
- Geometry, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Tangor is ten years old and has just learned how to compute the area of a triangle. He also worked out on his own that if all three vertices of a triangle have integer coordinates, the area is always an integer or half of an integer.
Today he is going the other way. Instead of measuring a triangle he already has, he picks an integer and tries to draw a triangle whose area is exactly . The vertices may sit only on the grid points of his graph paper.
The paper is divided into an by grid of square cells, and the only points he may use as vertices are the corners of those cells. Placing a coordinate system on the paper, a usable point is for integers and with and .
Given , and , find three grid points that form a triangle of area exactly , or report that no such triangle fits on the paper.
Input
The first line holds an integer , the number of test cases.
Each of the next lines holds three integers , and .
Constraints
Output
Print one line for each test case.
Many different triangles can have the same area, so the answer is fixed to a single canonical triangle. Let be the case number, counted from 1.
If , no triangle of area fits on the paper. In that case print
Case #k: IMPOSSIBLE
Otherwise let and . These satisfy and , and the triangle with vertices , and has area exactly . Print those vertices in that order:
Case #k: 0 0 N 1 w h
That is, print the six integers , , , , , separated by single spaces.