I am taking part in Project Euler, which is a set of mathematical problems, which require the development of algorithms and the writing of computer programs for their solutions.

Home page of Project Euler.

Home page of Project Euler.

The solution to each problem is a number which has to be typed in on the website. The website keeps track of all the problems that you have solved. Upon the submittal of a correct solution, you are granted access to a forum where you may discuss the method for solving the problem with other successful users.

I started last week Friday and have solved the first two problems so far out of  the current 254 (new problems are added regularly).

Two out of 254 problems solved.

Two out of 254 problems solved.

I plan to use the Fortran programming language throughout to improve my skills in that langauge. The first two problems were very easy:

  1. Find the sum of all multiples of 3 or 5 less than 1000.
  2. Find the sum of all even-valued terms in the Fibonacci sequence which do not exceed four million.

I simply used Fortran to write simple programs to calculate the sums. The third problem is giving me a headache:

Problematic third problem.

Problematic third problem.

The reason I have a headache is that 600,851,475,143 is about 300 times larger than the largest integer that a 32-bit computer can hold, 2,147,483,647.

I had a simple plan for this problem:

  1. Translate my prime number generating code from Visual Basic to Fortran and store it in a program called Primes.f95. DONE!
  2. Write the prime numbers to a text file called Primes.txt. DONE!
  3. Write another program, PrimeFactor.f95, for calculating the prime factors of an integer fed in by the user.
  4. PrimeFactor.f95 would contain an array, Primes(Size), which would be filled with primes read in from the Primes.txt text file.
  5. The fed-in integer would then be divided by the primes in the Primes(Size) array to find its prime factors.
  6. The largest of the prime factors I would then type into Project Euler and, E Voila!, have three problems solved.

One way to get past this is to specify the Primes(Size) array as of the REAL data type, instead of as an integer, because 600,851,475,143 is miniscule in comparison with the largest real number that a 32-bit computer can hold, 100,000,000,000,000,000,000,000,000,000,000,000,000 or 1E+38 .