Skip to content

Instantly share code, notes, and snippets.

@Buzz-Lightyear
Created November 5, 2014 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Buzz-Lightyear/1a4fcb5fe30e9f66f8d4 to your computer and use it in GitHub Desktop.
Save Buzz-Lightyear/1a4fcb5fe30e9f66f8d4 to your computer and use it in GitHub Desktop.
/*
Project Euler Question 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.
Display the sum of all the multiples of 3 or 5 below 1000.
*/
import java.util.*;
import java.lang.*;
import java.io.*;
class ProjectEulerProblem1
{
public static void main (String[] args) throws java.lang.Exception
{
int sum = 0;
for(int i = 3; i < 1000; i += 3)
sum += i;
for(int i = 5; i < 1000; i += 5)
sum += i;
for(int i = 15; i < 1000; i += 15)
sum -= i;
System.out.println(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment