fork download
  1. /**
  2. Abir3014
  3. **/
  4.  
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9.  
  10. typedef vector<ll> vi;
  11. typedef vector<pair<ll, ll>> vii;
  12. typedef multiset<pair<ll, ll>> msii;
  13. typedef multiset<ll> msi;
  14. typedef set<pair<ll, ll>> sii;
  15. typedef set<ll> si;
  16. typedef map<ll, ll> mii;
  17.  
  18.  
  19. #define recap(i,k,n) for(int i = k; i>=n; i--)
  20. #define rep(i,k,n) for(int i=k; i<n; i++)
  21. #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  22. #define for1(x, a, b) for(x=a; x<b; x++)
  23. #define for2(x, a, b) for(x=a, x>=b; x--)
  24. #define endl "\n"
  25. #define all(x) x.begin(), x.end()
  26. #define mp make_pair
  27. #define read freopen("input.txt","r",stdin)
  28. #define write freopen("output.txt","w",stdout)
  29. #define pb push_back
  30. #define ff first
  31. #define ss second
  32. #define bb begin
  33. #define mem(arr, x) memset(arr, x, sizeof(arr));
  34. #define arr_ub(arr, n, x) upper_bound(arr, arr+n, x)-arr
  35. #define arr_lb(arr, n, x) lower_bound(arr, arr+n, x)-arr
  36. #define u_p(v, x) upper_bound(v.begin(), v.end(), x)-v.begin()
  37. #define l_b(v, x) lower_bound(v.begin(), v.end(), x)-v.begin()
  38.  
  39.  
  40. const ll sz=1e6+123;
  41. #define INF 1000000000000000007
  42. #define MOD 1000000007
  43. #define stringLen 18446744073709551620
  44. #define pi 3.1415926536
  45.  
  46. inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
  47. inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
  48. inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
  49. inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
  50. inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
  51. inline ll modInverse(ll a) { return modPow(a, MOD-2); }
  52. inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
  53.  
  54.  
  55. //vi divisorList[sz];
  56. //ll divisorNumber[sz];
  57. //void findDivisor(ll n){
  58. // for(ll i=1; i<=n; i++){
  59. // for(ll j=i; j<=n; j+=i){
  60. // divisorList[j].pb(i);
  61. // divisorNumber[j]++;
  62. // }
  63. // }
  64. //}
  65.  
  66. //bool isPalindrome(string s){ll i=0,j=s.size()-1;for(i,j;i<=j;i++,j--){if(s[i]!=s[j]) return 0;}return 1;}
  67. ll gcd(ll a, ll b){return b==0? a: gcd(b, a%b);}
  68. //// lcm * gcd = a*b
  69. //ll lcm(ll a, ll b){if(a>b)swap(a, b);return a*(b/gcd(a, b));}
  70. //bool isPalindrome(string s){ ll i=0,j=s.size()-1;for(i,j;i<=j;i++,j--){if(s[i]!=s[j]) return 0;} return 1;}
  71. //bool isPowerofTwo(ll n){return (n && !(n&(n-1)));}
  72. //int count_one(ll n){int count=0;while(n){n &= (n-1);count++;}return count;}
  73. //string binRep(ll n){string s="";int f = 0;while(n>0){if(n%2){f=1;s+='1';}else s+='0';n/=2;}if(s.empty())return "0";else return s;}
  74. //int ctz(ll n){return __builtin_ctzll(n);}
  75. //int clz(ll n){return __builtin_clzll(n);}
  76. //int bitCount(ll n){return __builtin_popcountll(n);}
  77.  
  78. //bitset<sz>is_prime;
  79. //vi prime;
  80. //
  81. //void primeGen(int n){
  82. // for(int i=3; i<=n; i+=2)is_prime[i]=1;
  83. // int nn = sqrt(n)+1;
  84. // for(ll i=3; i<nn; i+=2){
  85. // if(is_prime[i]==0)continue;
  86. // for(int j=i*i; j<=n; j+=(i+i)){
  87. // is_prime[j]=0;
  88. // }
  89. // }
  90. // is_prime[2]=1;
  91. // prime.pb(2);
  92. // for(int i=3; i<=n; i+=2){
  93. // if(is_prime[i])prime.pb(i);
  94. // }
  95. //
  96. //}
  97. //
  98. //vector<long long>primeDivisors[sz];
  99. //long long primeDivisorNumbers[sz];
  100. //void findPrimeDivisors(long long n){
  101. // for(auto u:prime){
  102. // for(long long i = u; i<=n; i+=u){
  103. // primeDivisors[i].push_back(u);
  104. // primeDivisorNumbers[i]++;
  105. // }
  106. // }
  107. //}
  108. //
  109. //
  110. //vector<long long>factorization(long long n){
  111. // //O(sqrt(n)/ln(sqrt(n)) + log2 n)
  112. // vector<long long>factors;
  113. // for(auto u:prime){
  114. // if(1LL*u*u > n) break;
  115. // if(n%u==0){
  116. // // factors.push_back(u);//for generating unique factors keep this line here
  117. // while(n%(u)==0){
  118. // //factors.push_back(u);//for generating all factors keep this line here
  119. // n/=(u);
  120. // }
  121. // }
  122. // }
  123. // if(n>1)factors.push_back(n);
  124. // return factors;
  125. //}
  126. //
  127. //int NOD(long long n){
  128. // int res=1;
  129. // for(auto u:prime){
  130. // if(1LL*u*u > n)break;
  131. // if(n%u==0){
  132. // int count=1;
  133. // while(n%u==0){
  134. // n/=u;
  135. // count++;
  136. // }
  137. // res *= count;
  138. // }
  139. // }
  140. // if(n>1)res*=2;
  141. // return res;
  142. //}
  143.  
  144. ll test=0;
  145. void solve(){
  146. int a, b;
  147. cin>>a>>b;
  148.  
  149. if(gcd(a, b)>1){
  150. cout << 0 << endl;
  151. }
  152. else if((a%2==1 && b%2==0)||(a%2==0 && b%2==1)){
  153. cout << 1 << endl;
  154. }
  155. else if(a%2==1 && b%2==1){
  156. int x = min(a, b);
  157. int y = max(a, b);
  158. if(x==1){
  159. cout << 2 << endl;
  160. }
  161. else{
  162. int xxx = x-y%x;
  163. cout << min(2, xxx) << endl;
  164. }
  165. }
  166.  
  167. //cout<<"Case "<<++test<": "<<ans<<endl;
  168. //cout<<"Case #"<<++Case<<": ";
  169.  
  170. }
  171. int main(){
  172. boost;
  173. //read; write;
  174. int t; cin>>t; for(int i=1; i<=t; i++)
  175. solve();
  176.  
  177.  
  178. return 0;
  179. }
  180.  
  181.  
  182.  
  183.  
  184.  
Success #stdin #stdout 0s 5644KB
stdin
Standard input is empty
stdout
Standard output is empty