CF1909B.Make Almost Equal With Mod
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
⠀
You are given an array a1,a2,…,an of distinct positive integers. You have to do the following operation exactly once:
- choose a positive integer k ;
- for each i from 1 to n , replace ai with ai mod k† .
Find a value of k such that 1≤k≤1018 and the array a1,a2,…,an contains exactly 2 distinct values at the end of the operation. It can be shown that, under the constraints of the problem, at least one such k always exists. If there are multiple solutions, you can print any of them.
† a mod b denotes the remainder after dividing a by b . For example:
- 7 mod 3=1 since 7=3⋅2+1
- 15 mod 4=3 since 15=4⋅3+3
- 21 mod 1=0 since 21=21⋅1+0
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤500 ). The description of the test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤100 ) — the length of the array a .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤1017 ) — the initial state of the array. It is guaranteed that all the ai are distinct.
Note that there are no constraints on the sum of n over all test cases.
输出格式
For each test case, output a single integer: a value of k ( 1≤k≤1018 ) such that the array a1,a2,…,an contains exactly 2 distinct values at the end of the operation.
输入输出样例
输入#1
5 4 8 15 22 30 5 60 90 98 120 308 6 328 769 541 986 215 734 5 1000 2000 7000 11000 16000 2 2 1
输出#1
7 30 3 5000 1000000000000000000
说明/提示
In the first test case, you can choose k=7 . The array becomes [8 mod 7,15 mod 7,22 mod 7,30 mod 7]=[1,1,1,2] , which contains exactly 2 distinct values ( {1,2} ).
In the second test case, you can choose k=30 . The array becomes [0,0,8,0,8] , which contains exactly 2 distinct values ( {0,8} ). Note that choosing k=10 would also be a valid solution.
In the last test case, you can choose k=1018 . The array becomes [2,1] , which contains exactly 2 distinct values ( {1,2} ). Note that choosing k=1018+1 would not be valid, because 1≤k≤1018 must be true.