Problem link : https://www.codechef.com/problems/CHFGCD
#include
using namespace std;
int GCD(int X, int Y)
{
if (Y == 0)
return X;
return GCD(Y, X % Y);
}
int main(){
long long int T,X,Y;
int gcd;
cin>>T;
while(T–){
cin>>X>>Y;
if(GCD(X,Y)>1)
{
cout<<“0”<<endl;
}
else if(GCD(X,Y)<=1)
{
if(((X%2==0) || (Y%2==1) ) && ( (X%2==1) || (Y%2==0)))
{
cout<<"1"<<endl;
}
else if(X%2==1 && Y%2==1)
{
cout<<"2"<<endl;
}
}
}
return 0;
}
1
7 9
Your output: 1
Correct: 2
1 Like
replace “&&” by “||” → and by or as either of two can be true not both.
But still the o/p remains the same.
Yes…but why is it so?..where am i wrong?..at which step?
If i replace “&&” with “||” then i am getting 2 as o/p but still my solution is not getting accepted…Why?
You have to add one more condition inside this
if( __gcd(x,y+1)>1 or __gcd(x+1,y)>1) cout<<"1\n";
else cout<<"2\n";
this is to takle input like
1
3 5
Correct O/P :- 1
1 Like
check for testcases like this
9 25
o/p- 1
3 5
o/p-1
1 1
o/p-2
best would be to use
if (gcd(x+1,y)!=1||gcd(x,y+1)!=1)
cout<<1;
else
cout<<2;
1 Like
Okayy…that means the conditions which i wrote is not true for all the testcases and so this solution wasn’t accepted…right? @pkpawan123 @thunderboltz @draper_don @varunpitty21