so I was recently trying out a question and wrote some code but I couldn't manage to pass more than 3 test cases out of 5. the ques is: 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".
Input Format A single integer N
Constraints N <= 10^9
Output Format Two numbers X and Y denoting the rest of the numbers of the Pythagorean triplet in increasing order.
Sample Input 3 Sample Output 4 5
My Solution:
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
cin>>n;
if(n>=0 && n<=2){
cout<<"-1"<<endl;
}
else if (n%2==0){
cout<<pow((n/2),2)-1<<" "<<pow((n/2),2)+1<<endl;
}
else if (n%2==1){
cout<< 2*((n-1)/2)*((n+1)/2) <<" "<<pow((n+1)/2,2) + pow((n-1)/2,2)<<endl;
}
else{
cout<<"-1"<<endl;
}
return 0;
}
can someone suggest what am i missing in this ?