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.
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.
For each test case, output an integer which is the required answer.
3 4 7
4 4 4 4
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.