Pythagoras triplet

how to fing the triplets given one of the legs can u tell me the best approach?

You need to use formulaes to solve this question…pls refer to this…
long long int N;
cin>>N;
if(N==1 || N==2)
{
cout<<"-1";
}
else
{
if(N%2==0)
{
cout<<(N/2)*(N/2)-1<<" “<<(N * N)/4+1;
}
else
{
cout<<(N * N-1)/2<<” "<< (N * N +1)/2;
}
}

1 Like