consider this code:

```java
public static boolean isPrime(int n) {
    for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
    return n > 1;
}

public static int squareOf(int n) {
    int i = 0;
    while (i * i < n)
    i++;

    return i * i == n ? i: -1;
}

```

since (46340)*(46340)< Integer.MAX\_VALUE < (46341)*(46341), i\*i overflows.

what I expect then, is that for numbers bigger than (46340)\*(46340), isPrime either does not terminate, or eventually stops but gives some random answer.

what happens is for every single int < Integer.MAX\_VALUE, it gives a correct answer !! and for Integer.Max\_value it gives a wrong one. 

**Why** does this happen?

---

in squareOf, we have i \* i < n , instead of i \* i <= n:

for the range [(46 340)^2 + 1 , 2147483641]: it is correct, except for: {2147402577, 2147465721, 2147469348,
2147478505, 2147481513, 2147481513, 2147482825, 2147482929, 2147483280, 2147483536, 2147483556, 2147483609, 2147483620, 2147483641}

[2147483642 , Integer.MAX\_VALUE]: it seems to not terminate.

**why** does it give a correct answer **for a lot** of values?

**what's special** about the values where it gives a wrong answer?

**why** does it not terminate for values after 2147483641 ?