#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
if(a==0)
return b;
return gcd(b%a,a);
}
int main()
{
int t;
cin>>t;
while(t–){
ll x,y;
cin>>x>>y;
if(gcd(x,y)>1)
{cout<<“0”<<endl;}
else if(x%2==0||(y%2==0))
{
cout<<“1”<<endl;
}
else
{
cout<<“2”<<endl;
}
}
return 0;
}
Run your code with 3 and 7
Take this test case :-
1
3 5
Your O/P :- 2
Correct :- 1
According to your logic , if both numbers are odd, u are returning answer as 2 everytime, however this is not the case : Consider 3 & 5, if we add 1 to 5 , it becomes 3 & 6 and their gcd is 3, so the ans will be 1.
According to your logic we can’t say that if any of them is odd then answer is 2,
If you take case 1 : 3, 8 . Here 3, 8 + 1 => 3, 9 So answer is 1.
If both are prime like 3,7 ,so 3+ 1,7 + 1=>4,8 ,So answer is 2;