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.

About Jaroslaw Pawlak

I have done MSci in Computer Science at King’s College London and currently work as Software Engineer specialising in Java. I spend most of my time in front of computer improving my programming (and other) skills or just relaxing with a good game. I also train some sports but at the moment I am not a member of any club. I love cycling and volleyball, but I have also played a lot of football, tennis and trained martial arts.

Posted on June 17, 2011, in Project Euler. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: