题库练习 Three Days Grace
← 上一题 下一题 →

A15240 | Three Days Grace

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Ibti was thinking about a good title for this problem that would fit the round theme (numerus ternarium). He immediately thought about the third derivative, but that was pretty lame so he decided to include the best band in the world — [Three Days Grace](https://www.youtube.com/channel/UCJDON3eLf8709E9YfjAgLOw).

You are given a multiset $A$ with initial size $n$ , whose elements are integers between $1$ and $m$ . In one operation, do the following:

- select a value $x$ from the multiset $A$ , then
- select two integers $p$ and $q$ such that $p, q > 1$ and $p \cdot q = x$ . Insert $p$ and $q$ to $A$ , delete $x$ from $A$ .

Note that the size of the multiset $A$ increases by $1$ after each operation.

We define the balance of the multiset $A$ as $\max(a_i) - \min(a_i)$ . Find the minimum possible balance after performing any number (possible zero) of operations.

输入格式

The first line of the input contains a single integer $t$ ( $1 \le t \le 10^5$ ) — the number of test cases.

The second line of each test case contains two integers $n$ and $m$ ( $1 \le n \le 10^6$ , $1 \le m \le 5 \cdot 10^6$ ) — the initial size of the multiset, and the maximum value of an element.

The third line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le m$ ) — the elements in the initial multiset.

It is guaranteed that the sum of $n$ across all test cases does not exceed $10^6$ and the sum of $m$ across all test cases does not exceed $5 \cdot 10^6$ .

输出格式

For each test case, print a single integer — the minimum possible balance.

输入输出样例

输入 #1
4
5 10
2 4 2 4 2
3 50
12 2 3
2 40
6 35
2 5
1 5
输出 #1
0
1
2
4
C++ 编辑器
输入
输出