Monthly Archives: November 2008

Solution Problem 4 Project Euler

I have solved problem 4 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 4 is here

Problem004.java

The solution is a brute force approach. I initialize two numbers to 999 and then iterate down on each of them separately until we reach zero on both. At this point we should have the two three digit numbers that make up the largest palindrome.

Hope the solution is understandable. If not, don’t hesitate to put a comment. Continue reading

Posted in Uncategorized | Leave a comment

Solution to Problem 3 Project Euler

I have solved problem 3 of the Project Euler using java. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 3 is here

Problem003.java

Below I will try to describe the algorithm I used to solve the problem:

a) We will iterate starting at 3 to the number numberToGetLargestPrimeFactor / largestPrimeFactor . Where the numberToGetLargestPrimeFactor is initialized to 600851475143L and largestPrimeFactor is the largest prime number calculated up to that point in the iteraton, it is initialized at 1.

b) At each iteration we will check if the i divides numberToGetLargestPrimeFactor exactly.

c) If i divides numberToGetLargestPrimeFactor exactly then we will find out if i is a prime number.

d) To check if i is a prime number we do it by trying to divide i between the different numbers in the list of prime numbers. If it is divided by one of them then it means that i is not a prime number.

e) If i is a primer number then we store it in the list of primes. And we make largestPrimeFactor equal to the value of i.

Hope this helps in understanding the algorithm. Continue reading

Posted in Uncategorized | Leave a comment