Pythagoras Triplet

I did solve the problem but if i put 12, my answer is 35 and 37 and there is another solution which is 5 and 13… Both of them are correct.
#include
#include
using namespace std;

int main() {
int m,n,num,temp,temp1,temp2,temp3,a;
cin >> num;
if(num%2==0){
m=num/2;
n=1;
temp=pow(m,2)-pow(n,2);
temp1=pow(m,2)+pow(n,2);
}

if (num%2!=0){
    m=(num+1)/2;
    n=(num-1)/2;
    temp=2*m*n;
    temp1=pow(m,2)+pow(n,2);
}

temp2=pow(temp,2)+pow(num,2);

if(pow(temp1,2)==temp2){
    cout << temp << " " << temp1;
}

else{
    cout << "-1";
}

}

I have edited your code… Try to submit it now…

Thank you so much it worked but i have 3 queries for the same.

  1. What was my mistake? Is it because i used int instead of long? 2. Why you replaced library with <bits/stdc++.h>. 3. long lont int m,n,num,temp means that first two would be consider as long as rest all will be integer.

No, I have used long long int because of the large constraints of input given in your question, then library <bits/stdc++.h> is included so as to include all the header files in your program, so instead you can use <math.h> and iostream separately as well…and i have taken all values as long long int… and I have also included the condition when num==1 or num==2, then output would be -1, otherwise you would check for odd and even cases…