#include
#include
using namespace std;
int main() {
int a,b,c;
cin>>a;
b = (pow(a,2))/2;
c = b+1;
int p = pow(a,2);
int q = pow(b,2);
int r = pow(c,2);
if(p+q == r){
cout<<b<<" “<<c;
}
else{
cout<<”-1";
}
return 0;
}
#include
#include
using namespace std;
int main() {
int a,b,c;
cin>>a;
b = (pow(a,2))/2;
c = b+1;
int p = pow(a,2);
int q = pow(b,2);
int r = pow(c,2);
if(p+q == r){
cout<<b<<" “<<c;
}
else{
cout<<”-1";
}
return 0;
}
hi @pjindal393,
hi @pjindal393,
failing for large test case
If m>n>0 are integers, then (m2-n2, 2mn, m2-n2) is a Pythagorean triple. This is easily seen with a bit of algebra. Thus, plugging in various (m,n) will give various triples.
Now, our goal is to find a triple of the form (m2-n2, 2mn, m2-n2) in which our input value is one of the catheti. Note that the catheti are m2-n2 and 2mn. Also, note that the second cathetus is always even. Thus, it makes sense to consider two cases: