Well, you do have two variables called n. Which isn't helping you.
You are also making p an int. So, when you form p * p you are hoping that it stays within the range of an int. In the case of n=105 that is probably not true. On line 18, p only has to go up to (and including, where appropriate) the square root of n.
Basically, you are overflowing the maximum value that an int can hold.