CHFGCD getting WA

why this approach is wrong? and how can i correct it?

#include <bits/stdc++.h>

using namespace std;

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int N;
cin>>N;
if(1<= N <=10^5) {
for(int i=0;i<N;i++){
    long long x,y;
    cin>>x>>y;
    int ops=0;//number of operations
    float gcd;
    if(not(1<= x,y <= 10^9)) {
        goto end;
    }
   	gcd=__gcd(x,y);
    //cout<<gcd<<endl;
    
    while(gcd==1){
        if(x%2!=0){
            x++;
            ops++;
    }
    else if(y%2!=0){
            y++;
            ops++;
    }
    gcd=__gcd(x,y);
}

//cout<<gcd<<endl;
cout<<ops<<endl;
end:;
    
}}

}

Consider the test input:

1
3 5
1 Like

it gives 2 for input
3 5
so its incrementing 3 two times to make it equal to 5 :confused:
how can i correct it :frowning:

At this point, you should probably just read the Editorial :slight_smile:

Oh thank you <3 btw i didn’t even knew what the editorial is
Thanks again :slight_smile: <3

1 Like