can some one help me to find any fault in this code for CHFFIELD

For : http://www.codechef.com/CDSM2014/problems/CHFFIELD/

class ChefAndTheField {

static boolean isPrime(int num) {
	if (num == 2) {
		return true;
	} else if (num == 1 || num % 2 == 0)
		return false;
	for (int i = 3; i * i <= num; i += 2)
		if (num % i == 0)
			return false;
	return true;
}

public static void main(String[] args) throws java.lang.Exception {
	java.util.Scanner sc=new java.util.Scanner(System.in);
	int l, b;
	int testCases = sc.nextInt();
	if(testCases>0){
	for (int i = 0; i < testCases; i++) {
		l = sc.nextInt();
		b = sc.nextInt();
		if(1<= l && l <=1000000 && 1<= b && b <=1000000){
		while (isPrime(l)) {
			l--;
		}
		while (isPrime(b)) {
			b--;
		}
		System.out.println(l * b);

	}
}

}}}

Use long data type for l and b as 1000000*1000000 crosses range of int

1 Like