Ankit_132

B

Nov 29th, 2023
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {
  12.         int a, b;
  13.         cin>>a>>b;
  14.  
  15.         int x = 0, y = 0;
  16.  
  17.         while((b-x)>1 && (a+x)%(b-x) != 0)
  18.             x++;
  19.         while((a-y)>1 && (a-y)%(b+y) != 0)
  20.             y++;
  21.            
  22.         if((a-y)%(b+y))     y = 1e9;
  23.  
  24.         cout<<min(x, y)<<"\n";
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment