I recently started working on the #projecteuler100 challenge, and I thought I would share how I solved the problems on here. Here’s a complete walkthrough to Project Euler problem 1.

Note: I’ve written all of my solutions in Java, but the concept is the same in any language.

Project Euler Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

You can view my solution to this problem here.

To get started with problem 1, we first need a loop that will iterate over every number from 0 to 1000 (This is because Project Euler problem 1 states we want to find all of the multiples of 3 or 5 below 100. You can implement this in a variety of ways, but I chose to use a simple for-loop. We also need some kind of variable that will hold our sum.

int sum;
for (int i = 0; i < 1000; i++) {

Within the for loop, we want to check if the number is divisible by either 3 or 5. If it is, we then want to add that number to the sum. To check for divisibility, we can just use the modulus operator to check for a remainder of 0.

if (i % 3 == 0 || i % 5 == 0) {
  sum += i;

Finally, we can output the sum of all the values to the console.


Read up on other Project Euler solutions on the project euler category of this website.

If you feel like this article has helped you, please do share this website with your friends. Follow me on Twitter and GitHub to receive updates on my coding work.