#GL0000138. Rút gọn phân số dạng tích (Reducing Fractions)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Rút gọn phân số dạng tích (Reducing Fractions)
Reducing Fractions
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
The Galactic Empire represents a positive fraction using two arrays of positive integers. The numerator is the product of the first array, and the denominator is the product of the second one:
Output two new arrays representing exactly the same value , where the resulting numerator and denominator are coprime. The arrays may have different lengths from the input as long as the output bounds are respected. Any valid reduced representation is accepted. The original products may be too large for fixed-width integers.
Input
The first line contains . The second line contains integers ; the third contains integers .
Output
Print with , followed by numerator factors and denominator factors. Every printed factor must be in . Their products must represent the original fraction in reduced form.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4 3
2 5 10 20
100 1 3
Output
4 3
2 5 2 1
1 1 3
Explanation
The original products are and . Dividing by their GCD gives the reduced fraction . The output arrays have products and , which are coprime.