Prime Factorization Program in Java

后端 未结 12 1702
自闭症患者
自闭症患者 2021-01-03 11:11

I am working on a prime factorization program implemented in Java. The goal is to find the largest prime factor of 600851475143 (Project Euler problem 3). I think I have m

12条回答
  •  轮回少年
    2021-01-03 12:06

    I think you're confused because there is no iff [if-and-only-if] operator.

    Going to the square root of the integer in question is a good shortcut. All that remains is checking if the number within that loop divides evenly. That's simply [big number] % i == 0. There is no reason for your Prime function.

    Since you are looking for the largest divisor, another trick would be to start from the highest integer less than the square root and go i--.

    Like others have said, ultimately, this is brutally slow.

提交回复
热议问题