Make Equal With Mod solution codeforces – You are given an array of 𝑛n non-negative integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an. You can make the following operation: choose an integer 𝑥≥2x≥2 and replace each number of the array by the remainder when dividing that number by 𝑥x, that is, for all 1≤𝑖≤𝑛1≤i≤n set 𝑎𝑖ai to 𝑎𝑖mod𝑥aimodx.
Make Equal With Mod solution codeforces
Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.
The input consists of multiple test cases. The first line contains a single integer 𝑡t (1≤𝑡≤1041≤t≤104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer 𝑛n (1≤𝑛≤1051≤n≤105) — the length of the array.
The second line of each test case contains 𝑛n integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an (0≤𝑎𝑖≤1090≤ai≤109) where 𝑎𝑖ai is the 𝑖i-th element of the array.
The sum of 𝑛n for all test cases is at most 2⋅1052⋅105.
Make Equal With Mod solution codeforces
For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO.
You may print each letter in any case (for example, “YES”, “Yes”, “yes”, “yEs” will all be recognized as a positive answer).
4 4 2 5 6 8 3 1 1 1 5 4 1 7 0 8 4 5 9 17 5
YES YES NO YES
Make Equal With Mod solution codeforces
In the first test case, one can apply the operation with 𝑥=3x=3 to obtain the array [2,2,0,0][2,2,0,0], and then apply the operation with 𝑥=2x=2 to obtain [0,0,0,0][0,0,0,0].
In the second test case, all numbers are already equal.
In the fourth test case, applying the operation with 𝑥=4x=4 results in the array [1,1,1,1][1,1,1,1].