Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int a, b;
- cin>>a>>b;
- int x = 0, y = 0;
- while((b-x)>1 && (a+x)%(b-x) != 0)
- x++;
- while((a-y)>1 && (a-y)%(b+y) != 0)
- y++;
- if((a-y)%(b+y)) y = 1e9;
- cout<<min(x, y)<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment