My code above is passing 3 out 5 test cases , unable to figure out what cases I am missing.Kindly help.
Pythagoras Triplets
Your code is not producing correct results for large test cases, like ,
99999993
Your output :
237459736 237459737
Actual output : 4999999300000024 4999999300000025
So , I would recommend you to use the following approach,
if(n%2!=0)
then
p=(n+1)/2;
q=(n-1)/2;
b=2pq;
c=(pp)+(qq);
cout<<b<<" "<<c;
else
p=n/2;
q=1;
a=(p+q)(p-q);
c=(pp)+(q*q);
cout<<a<<" "<<c;
Made the suggested changes but now it does not pass any test case. Could you please explain how my original code is not giving the right results for a large integer ?
Ok, I check the code and let u know…
I have edited your code, try to submit it now,