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.

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.

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

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

Input : 
15 4
19 5 

Output : 

to report an issue on this page.


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


All Submissions

My Submissions:

Login to access your submissions.