2 test cases not passed in pythagoras triplet problem

the last 2 test cases from pythagoras problem cannot be passed …
please reply
CODE :

import java.util.*;
public class Main {
static void evaluate(int n){
if (n <= 2)
System.out.print("-1");
else if(n % 2 == 0){
int var = 1 * n * n / 4;
System.out.print(var - 1 + " “);
System.out.print(var + 1);
}else if(n % 2 != 0){
int var = 1 * n * n + 1;
System.out.print(var / 2 - 1 + " “);
System.out.print(var / 2);
}else
System.out.print(”-1”);
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
evaluate(n);
}
}

hey @amigarg2001_4d6124603ec7a2bd
There is just a minor change in your code.Just look at the Constraint on N(0<N<10^9).
so you just have to take instead of int to long as datatype for var variable.
2nd Change is : make input type of n to long and also change argument to long of method evaluate.
Below is the code after editing it (look for change comments for edits)
PLEASE PROVIDE ME A RATING AND MAKE THE DOUBT RESOLVED IF IT IS RESOLVED
import java.util.*;

public class Main {

static void evaluate(long n){

if (n <= 2)

System.out.print("-1");

else if(n % 2 == 0){

//change

long var = n * n / 4;

System.out.print(var - 1 + " ");

System.out.print(var + 1);

}else if(n % 2 != 0){

//Change

long var = n * n + 1;

System.out.print(var / 2 - 1+" ");

System.out.print(var / 2);

}

else

System.out.print(-1);

}

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

//Change

long n = scan.nextInt();

    evaluate(n);

}

}

Hey @amigarg2001_4d6124603ec7a2bd Since there is no response from you.I am marking this doubt as resolved. If you still have any then can reopen it.

1 Like

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.

1 Like