Help in Split Sum- Insomia

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while(T–) {
long long n,m;
cin>>n>>m;
long long sum=(n*(n+1))/2,sa=0,sb=0;
if(m>sum||((sum+m)%2)!=0)
cout<<“No”<<endl;
else{
sa=(sum+m)/2;
sb=sum-sa;
if(sa-sb==m){
if(gcd(sa,sb)==1)
cout<<“Yes”<<endl;
else
cout<<“No”<<endl;
}
else{
sb=(sum+m)/2;
sa=sum-sb;
if(gcd(sb,sa)==1)
cout<<“Yes”<<endl;
else
cout<<“No”<<endl;
}
}

    }
 
    return 0;
} 

WHAT WRONG WITH THIS SPLIT SUMS INSOMNIA HELPP

1 Like

Here, is your corrected sol. https://www.codechef.com/viewsolution/18032664
Your algo is correct. But, Just convert int to long long int in gcd fn. as a,b,and gcd(a,b) can also be in range of 10^18. :). It will give AC verdict. Small diff btw WA and AC. Happy Coding :slight_smile: