Least Multiple

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

Given a positive integer M, Bob needs to find the minimum positive integer N so that N!0(modM).

Since M is huge, Bob will give you K integers, denoted as e1,e2,,eK, such that M=i=1Kpiei, where pi is the i-th smallest prime number. It is guaranteed that piei1018

Input Specification

The first line of input contains an integer T (1T104), the number of test cases.

Each of the following T blocks contains two lines of input. The first line contains an integer K (1K100), the number of prime factors. The second line contains K integers ei (0piei1018), indicating the i-th prime's exponent.

Output Specification

Output one integer for each test case, the smallest positive integer N so that N!0(modM).

Constraints

Subtask Points Additional constraints
1 10 T=1, piei105.
2 25 T1000, piei1000.
3 30 T103, piei1018.
4 35 No additional constraints.

Sample Input

Copy
1
5
1 1 1 1 1

Sample Output

Copy
11

Explanation

M=21×31×51×71×111=2310, and the minimum N is 11.


Comments

There are no comments at the moment.