Greater Integer, Better LCM
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given three positive integers , you should find two non-negative integers that and minimize . Print the minimum . Here will be given in format where p_i, q_i denotes the primary factor and its power respectively.

Hint: you can use "__int128_t" in C++ to handle 128-bit integers.

输入描述:

The first line contains one integer .

Following lines each contains two integers .

Following one line contains two integers , where .

It's guaranteed that p_is are all primes and .

输出描述:

Output one line only containing one integer, denoting the answer.
示例1

输入

复制
2
2 3
3 1
7 9

输出

复制
4

说明

c = 2^3 \times 3^1 = 24, and one possible scheme is : x = 1, y = 3~(\mathrm{lcm}(a+x, b+y) = \mathrm{lcm}(7+1, 9+3) = \mathrm{lcm}(8, 12) = 24).