#P10383. Simplest Fraction Representation

    ID: 12390 Type: Default 1000ms 256MiB

Simplest Fraction Representation

Simplest Fraction Representation

Given two sequences of positive integers, a1, a2, ..., an and b1, b2, ..., bm, consider the fraction

$$\frac{\displaystyle\prod_{i=1}^n a_i}{\displaystyle\prod_{j=1}^m b_j}$$

Express this fraction in its simplest form as \(\frac{p}{q}\) and output the values p and q separated by a space.

Additionally, an extra integer C is provided which indicates the Subtask of the dataset.

You are to compute the products, reduce the fraction by their greatest common divisor, and print the result.

Note: All input values are positive integers.

inputFormat

The input consists of three lines:

  1. The first line contains three integers n, m and C, where n is the number of elements in the first sequence, m is the number of elements in the second sequence, and C is an extra integer indicating the subtask.
  2. The second line contains n integers separated by spaces representing the array \(a_i\).
  3. The third line contains m integers separated by spaces representing the array \(b_j\).

outputFormat

Output two integers p and q separated by a space, where \(\frac{p}{q}\) is the fraction in its simplest form.

sample

2 2 1
1 2
1 3
2 3