Problem list
Log in
#coci00201 · COCI 2011/2012 Contest 2

Zadaća

Silver II 1.0 s 32 MB

Mirko has received a homework assignment to compute the greatest common divisor of the two positive integers $A$ and $B$. Since the numbers are quite large, the teacher provided him with $N$ smaller integers whose product is $A$, and $M$ integers with product $B$.

Mirko would like to verify his result, so he has asked you to write a program to solve his problem.

If the result is more than $9$ digits long, output only the last $9$ digits.

Input

The first line of input contains the positive integer $N$ ($1 \le N \le 1000$).

The second line of input contains $N$ space-separated positive integers less than $1,000,000,000$, whose product is the number $A$.

The third line of input contains the positive integer $M$ ($1 \le M \le 1000$).

The fourth line of input contains $M$ space-separated positive integers less than $1,000,000,000$, whose product is the number $B$.

Output

The first and only line of output must contain the greatest common divisor of numbers $A$ and $B$. If the result is more than $9$ digits long, output only the last (least significant) $9$ digits.

Note: In the third sample, the result has more than $9$ digits, so only the last $9$ digits (with leading zeros) are printed.

Example 1

Input
3
2 3 5
2
4 5
Output
10

Example 2

Input
4
6 2 3 4
1
1
Output
1

Example 3

Input
3
358572 83391967 82
3
50229961 1091444 8863
Output
000012028
Source
COCI 2011/2012 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code