import java.util.;
public class Main {
public static void main(String args[]) {
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
int a= sc.nextInt();
if (a<=2){
System.out.print("-1");
}
else if (a % 2 == 1){
int num = (aa-1)/2;
System.out.print(num + " ");
System.out.print(num+1);
}
else if (a % 2 == 0){
int num = (a*a-4)/4;
System.out.print(num + " ");
System.out.print(num+2);
}
}
}
My two test cases are wrong plese reviwe my code tell me how could i improve this
@er13aashishgupta_144ebaf32c98e77e Since Output can be very very large instead of using int use long variable to store the answer.
I did that but again same problem\
@er13aashishgupta_144ebaf32c98e77e Since input value can also be greater (10^9). Therefore your a should also be of type long, not int. Corrected Code :
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
long a= sc.nextInt();
if (a<=2){
System.out.print("-1");
}
else if (a % 2 == 1){
long num = (a*a-1)/2;
System.out.print(num + " ");
System.out.print(num+1);
}
else if (a % 2 == 0){
long num = (a*a-4)/4;
System.out.print(num + " ");
System.out.print(num+2);
}
}
}