 Timer is Running

Mr. Modulo and Arrays
##### Submissions: 506   Accuracy: 27.48%   Difficulty: Easy   Marks: 2

Mr. Modulo lives up to his name and is always busy taking the modulo of numbers and make new problems. Now he comes up with another problem. He has an array with n elements and wants to find the maximum value of modulo among all the pairs in the array. Or, given an array of n integers, find the maximum value of arr[i] mod arr[j] where arr[i] >= arr[j] and 1 <= i, j <= n.
Mr. Modulo needs some help to solve this problem. Help him to find this maximum value of modulo.

Input:
The first line of the input contains an integer T which denotes the number of test cases to follow. Each test case contains the number of elements in the array a[] as n and next line contains space separated n elements in the array.

Output:
For each test case, output an integer which is the required answer.

Constraints:
1<=T<=10
1<=n<=100000
1<=a[i]<=10000

Example:
Input:

2
3
3 4 7
4
4 4 4 4

Output:
3
0

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.