#P7616. GCD of Products

    ID: 20809 Type: Default 1000ms 256MiB

GCD of Products

GCD of Products

You are given two lists of positive integers: the first list contains N numbers \(A_1, A_2, \ldots, A_N\), and the second list contains M numbers \(B_1, B_2, \ldots, B_M\). Your task is to compute the greatest common divisor (GCD) of the product of all numbers in the first list and the product of all numbers in the second list. In mathematical notation, you need to find

[ \gcd\Biggl(\prod_{i=1}^{N} A_i,, \prod_{i=1}^{M} B_i\Biggr)]

Note that the products can be very large but the use of appropriate integer types or libraries should allow you to compute the answer correctly.

inputFormat

The first line contains two integers N and M, representing the number of integers in the first and second list respectively.

The second line contains N positive integers \(A_1, A_2, \ldots, A_N\) separated by spaces.

The third line contains M positive integers \(B_1, B_2, \ldots, B_M\) separated by spaces.

outputFormat

Output a single integer which is the result of \(\gcd(\prod_{i=1}^{N} A_i, \prod_{i=1}^{M} B_i)\).

sample

2 2
12 15
10 20
20

</p>