Please provide a hint or solution for the problem as I am unable to solve.
Pythagorean Triplets : Hint
logic:
Reference Code:
// pythagorean_triplet.cpp
/*
Given a number N (denoting one of the legs of the triangle),
Print its Pythagoras pair in increasing order if they exist. Otherwise, print "-1".
*/
#include <iostream>
using namespace std ;
int main()
{
long long int n;
cin>>n;
if(n<3)
cout<<"-1"; // if n<3 then pythagoreon triplet is not form
else // if n>3 then only pythagoreon triplet is form
{
if(n%2==0)
{
cout<< (((n/2)*(n/2))-(1)) <<" " << (((n/2)*(n/2))+1) ;
}
else
cout<< (2*((n+1)/2)*((n-1)/2)) <<" " << ((((n+1)/2)*((n+1)/2))+(((n-1)/2)*((n-1)/2)));
}
return 0;
}
if you have further doubt feel free to ask
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
