Knowing PHP well, I am finding JAVA to be superincredibly rigid.
John Sing wrote:right now my loop that runs 2,000,000 times seems to be a bit much for java to handle because it freezes around the 90,000 range. How can I improve my code and get it to work? Thanks.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
I hate signatures!
Piet Souris wrote:pointing OP to the 'Sieve' is as far as I would go. ... So please don't give code.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
The whole idea of Project Euler is to make people think about algorithms; you are supposed to find an efficient algorithm for finding prime numbers. Creating a sieve of Eratosthenes with an array or (good idea whoever said that) a BitSet is probably much faster than testing each number for primeness. Also remember you do not have to iterate the whole range, so your sieve creating algorithm doesn't run in quadratic time.Winston Gutkowski wrote:. . . OK, well first off, your line 10 check is extremely wasteful. You don't have to check all divisors from 2 to x or even close.
You do not need to check all of them. A little thought will allow you to reduce your search space greatly.. . . You only need to check prime divisors, . . .
Campbell Ritchie wrote:The whole idea of Project Euler is to make people think about algorithms; you are supposed to find an efficient algorithm for finding prime numbers. Creating a sieve of Eratosthenes with an array or (good idea whoever said that) a BitSet is probably much faster than testing each number for primeness.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:John asked us to critique his code which  and here I agree with Piet  we have signally failed to do.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
Carey Brown wrote:
Hint: what's the maximum possible prime you need to check for any X?
There's a way to do it better  find it. Edison. A better tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
