## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Three Days Grace Codeforces Solution

E. Three Days Grace
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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\left({a}_{i}\right)-min\left({a}_{i}\right)$. Find the minimum possible balance after

Solution Click Below:-  👉
👇👇👇👇👇

performing any number (possible zero) of operations.

Input

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

The Third Three Number Problem Codeforces Solution

Almost Ternary Matrix Codeforces Solution

The Third Problem Codeforces Solution

Almost Triple Deletions CodeForces Solution

Three Days Grace Codeforces Solution

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},\dots ,{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}$.