文理学院程序设计在线练习


Biggest remainder

Time Limit: 2 Second(s)    Memory Limit: 128 MB

Total Submission(s): 11   Accepted Submission(s): 5
Problem Description

Give you an array A, the length of array is N. we need you to find the max value of Ai MOD Aj(Ai≥Aj).

Input

The first line contains an integer T, represents the number of testcases.
For each testcase, the first line contains an integer N;
the second line contains N integers, represents A1,A2,….,AN; (T<=20,1<=N<=100000,1<=Ai<=1000000).

Output

For each testcase, output one line contains an integer represents the max value of Ai MOD Aj.

Sample Input
1
3
3 4 5
Sample Output
2
Source

2017绍兴市技能竞赛