You have written an infinite loop: 600851475143L
is greater than the maximum value that can be stored in an int
, so i <= x
will always be true
.
Changing i
and all the other relevant variables to long
may solve this issue, but you'll still have to rethink your algorithm. Checking if 600851475143 numbers are prime is just going to take too long.
Hint: once you have found a number that divides x
, you can divide x
by that number... (Hope this doesn't spoil the fun)