the else part (if n%2==0). the hypotenuse value is okay but other is failing.
Failed test cases
Hey @anirudhkaaul
#include<iostream>
#include<math.h>
using namespace std;
int main() {
long long N;//long long to avoid overflow
long long a =0;//long long to avoid overflow
long long b = 0;//long long to avoid overflow
long long c =0;//long long to avoid overflow
long long m =0; //long long to avoid overflow
long long n =0;//long long to avoid overflow
cin>>N;
if(N<3){//added this case
cout<<-1<<endl;
return 0;
}
if(N%2==0){
m = N/2;
n = 1;
a = (m*m)-(n*n);//m*m here
b = 2*(m*n);
c = (m*m)+(n*n);
}
else{
m =(int)(N+1)/2;
n = (int)(N-1)/2;
a = (N*N-1)/2;//updated
b = 2*(m*n);
c = (N*N+1)/2;//updated
}
if(N!=a){
cout<<a<<" "<<c<<endl;
}
else{
cout<<b<<" "<<c<<endl;
}
return 0;
}
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.