Factorization of Quadratic Formula
InterviewTime limit1sMemory limit1024 MB
Given integers a, b, c of ax^2 + bx + c, find integers p, q, r, s so that it equals (px + q)(rx + s), or report Impossible.
- Level
Medium4 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
As the first step in algebra, students learn quadratic formulas and their factorization. Factorization is often a heavy burden for them. A large number of students never master it, so they cannot appreciate the elegance of advanced algebra. Factorization may even increase the number of people who hate mathematics.
This problem asks you to write a program that helps students in an algebra course. Given a quadratic formula, the program reports whether it can be factorized into two linear formulas, and if so, gives the factorization. All coefficients in this problem are integers.
The coefficients , , and of the quadratic formula are given. They are integers with absolute values at most 10000. The program must find integers , , , and such that . Since only integer coefficients are allowed, some formulas cannot be factorized this way. In that case, the program reports that the factorization is impossible.
Input
The input is a sequence of lines, each describing one quadratic formula. Each line has the format
where , , and are integers separated by spaces. They satisfy the following inequalities.
The greatest common divisor of , , and is 1. No integer greater than 1 divides all three.
The end of input is a line containing three 0's.
Output
For each input line, print the four integers , , , and on one line, in this order, if a factorization exists. Separate the integers with one or more spaces. If the factorization is impossible, print only the word "Impossible".
The four coefficients must satisfy the following conditions.
, or and
These conditions, together with the fact that the greatest common divisor of , , and is 1, make the answer unique. Once you find a factorization, you do not need to look for another one.