#P1482. Product Fraction Position in Cantor's Table
Product Fraction Position in Cantor's Table
Product Fraction Position in Cantor's Table
This problem is based on one of the famous proofs in modern mathematics by Georg Cantor which shows that the set of rational numbers is enumerable. Cantor used the following table:
$$\begin{matrix} 1/1 & 1/2 & 1/3 & 1/4 & 1/5 & \cdots \\ 2/1 & 2/2 & 2/3 & 2/4 & \cdots \\ 3/1 & 3/2 & 3/3 & \cdots \\ 4/1 & 4/2 & \cdots \\ 5/1 & \cdots \end{matrix}$$In this problem, you are given two fractions (not necessarily in simplest form). You need to compute their product, reduce the result to its simplest form, and then determine the position of the resulting fraction in the above table. In the table, the fraction \(\frac{a}{b}\) is located in the b-th column and the a-th row. Note that if the product is an integer \(a\) (i.e. it can be considered as \(\frac{a}{1}\)) or is of the form \(\frac{1}{a}\), then treat it as \(\frac{a}{1}\) or \(\frac{1}{a}\) respectively.
inputFormat
The input consists of a single line with two fractions separated by a space. Each fraction is given in the format A/B
where A and B are positive integers.
For example:
1/2 1/3
outputFormat
Output two integers separated by a space: the first integer is the column number and the second integer is the row number where the simplified product fraction \(\frac{\text{numerator}}{\text{denom}}\) appears in Cantor's table.
For instance, if the simplified fraction is \(\frac{1}{6}\), output: 6 1
.
sample
1/2 1/3
6 1