Sharing
Submissions: 472   Accuracy:

23.74%

  Difficulty: Easy   Marks: 2

As we know that sharing is a good policy, but Rohan's younger brother Ted is very mischievous. He is very fond of chocolates. But actually he can't reach to the height of the kitchen shelf, where 'N' chocolates are kept. So, he can call any number of family members from 1 to K. But there is a condition that when members come and reach out to shelf, they divide all the chocolates between them in such a way that everyone will get the same amount of chocolates and this amount is maximal possible. If chocolates are left, Ted can take them after they go. Since Ted is not so smart, you need to tell him how much maximum chocolates he will get if he call maximum of 'K' people.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two space separated integers N and K.


Output: 
For each test case in a new line output - the maximum possible number of chocolates Ted can get.

 

Constraints:
1 ≤ T ≤ 50
1 ≤ N, K ≤ 105


Example:
Input : 
2
15 4
19 5 

Output : 
3
4

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

Contributor: Mohit Gupta :)
Author: Mohit Gupta 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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.