I have written the code for Pythagoras Triplet. It seems correct to me, and the given test cases are running. However, when I’m submitting the code,2 out of 5 test cases are showing incorrect answer. Can you please tell me what is the problem with my code? The link for code is-
I am also posting my code below-
#include
#include<math.h>
using namespace std;
int main()
{
int n,a,b,c1,c2;
cin>>n;
if(n%2==0)
{
a=n/2;
b=1;
c1=pow(a,2)-1;
c2=pow(a,2)+1;
if((c1==0)||((pow(c1,2)+pow(n,2))!=pow(c2,2)))
cout<<"-1";
else
cout<<pow(a,2)-1<<" “<<pow(a,2)+1;
}
else
{
a=(n+1)/2;
if(a<0)
a=-a;
b=(n-1)/2;
if(b<0)
b=-b;
c1=2ab;
c2=pow(a,2)+pow(b,2);
if((c1==0)||((pow(c1,2)+pow(n,2))!=pow(c2,2)))
cout<<”-1";
else
cout<<2ab<<" "<<pow(a,2)+pow(b,2);
}
}