What’s the best data structure (in java) for the task of loading 51 million primes and then iterating over them?
I need to know, for example, the primes that are between 1000000000 and that same number minus 100000.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A binary search isn’t going to be wonderful for this data, since the first half of the primes are going to be closer to each other than the last half of them.
You might be able to improve on your search by knowing how many primes there are under x. Maybe skew the cut by using the approximation mentioned in the link.
My first try would be this. I’d have two arrays.
I’d get a rough position with array 2 before doing anything with array 1.