Pythagoras triplet

#include
#include
using namespace std;
int main() {
long long int n;
cin>>n ;
if(n<=pow(10,9))
if(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!=0){
cout<<2*((n+1)/2)*((n-1)/2)<<’ '<<pow((n+1)/2,2) + pow((n-1)/2, 2)<<endl;
}

return 0;

}

Test caes 3 and 4 are shown as being failed.
please help me with the errors in the code

hi @karanaggarwal708_71435e604edb5689,
code is absolutely correct just dont use power function
here’s the updated one https://ide.codingblocks.com/s/658505

reason :
The problem is that double (and floating-point numbers in general) aren’t exact and the math functions in the standard library also use approximate formulae to do the calculations. If you call pow(2, 10) , you may get 1023.999375 , for example (which is then, depending on the context, may be truncated down to 1023 ).

hope this solves the issue :slight_smile:

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.