Prime numbers in Project Euler
Many of the problems in Project Euler use prime numbers. Starting from the problem “is N prime?” and ending at counting the total number of divisors of a number. I have started from writing the class Prime with the only method isPrime(long) using brute solution, but over time I have been extending this class – adding new methods and upgrading existing ones. Now, I think it contains much enough of utilities to share it with you ;)
Probably you may find something better for this on the Internet, but we all struggle with Project Euler so why not to help each other? Moreover you may help me improving this class ;)
Here is the code.
If you know that you are going to work with great prime numbers, I suggest invoking sieve(int) method first – it finds prime numbers using Sieve of Eratosthenes. Otherwise prime numbers are found dynamically when necessary.