so I wanna find the largest prime factor and the loop kinda stops at some number (pls dont give optimized code rather tell me why the loop doesnt continue)
code:
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger num = new BigInteger("600851475143");
BigInteger erg = BigInteger.ZERO;
for (BigInteger i = BigInteger.ONE; i.compareTo(num) <= 0; i = i.add(BigInteger.ONE)) {
if (isPrime(i) && num.mod(i).equals(BigInteger.ZERO)) {
erg = i;
System.out.println(erg);
}
}
System.out.println(erg);
}
static boolean isPrime(BigInteger num)
{
if(num.compareTo(BigInteger.ONE) <= 0)
{
return false;
}
for(BigInteger i = BigInteger.TWO; i.multiply(i).compareTo(num) <= 0; i = i.add(BigInteger.ONE))
{
if(num.mod(i).equals(BigInteger.ZERO)) {
return false;
}
}
return true;
}
}
this is my output and its still in the loop:
https://cdn.discordapp.com/attachments/1116821865772626020/1166473603194310766/image.png?ex=654a9e33&is=65382933&hm=6c4a6f8141d5665421ccc7d113ef26fbb3deaa7e5972cb7efb00c57a906c5ee3&