Distribute Cookies Chef is making cookies for N kids. He wants to give everyone an equal…
Jump to turn (10)
- 1Distribute Cookies Chef is making cookies for N kids. He wants to give everyone
- 2Your Output 2 2 1 0 required output: 2 2 3 0 dont explain me anything just give
- 3Maximum Distance Permutations Define the distance between 22 permutations^{\dag}
- 4output required: 1 1 1 2 2 1 1 2 3 3 1 2 code output: 1 1 1 2 2 1 1 2 3 3 2 1
- 5#include void generatePermutations(int N) { // Permutation A: 1 to N for (int i
- 6Sum of N Define f(X)f(X) as the largest divisor of XX other than XX itself. For
- 7#include long long f(long long x){ for(long long i=x/2;i>=1;--i){ if(x%i == 0){
- 8#include long long f(long long x){ for(long long i=x/2;i>=1;--i){ if(x%i == 0){
- 9Your Output 0 0 288 required output: 4 15 36
- 10Status :Time limit exceeded Time limit1 secs Memory limit1.5 GB Source Limit5000
- User
Distribute Cookies Chef is making cookies for N kids. He wants to give everyone an equal number of cookies. He must give at least 1 cookie to each kid.
Chef already has M cookies. He can destroy or make 1 cookie in 1 second.
Find the minimum time after which he can evenly distribute the cookies between all kids.
Input Format The first line of input will contain a single integer T, denoting the number of test cases. Each test case consists of a single line of input. The first and only line of each test case contains N and M - the number of kids and the initial number of cookies. Output Format For each test case, output on a new line the minimum time such that Chef can evenly distribute all his cookies.
Constraints 1 \le T \le 10^41≤T≤10 4
1 \le N, M \le 10^91≤N,M≤10 9
Sample 1: Input: 4 5 17 5 18 4 1 2 18 Output: 2 2 3 0 Explanation: Test Case 1 : Chef destroys 2 cookies to have 15 cookies total. This takes 2 seconds. Now, he can distribute all his cookies by giving every kid 3 cookies each.
Test Case 2 : Chef makes 2 cookies to have 20 cookies total. This takes 2 seconds again. Now, he can distribute all his cookies by giving every kid 4 cookies each.