Sharing
Easy Accuracy: 23.51% Submissions: 485 Points: 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

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.