Skip to content

Instantly share code, notes, and snippets.

@dan-dm
Forked from brunoperezm/Problema_EULER_1.java
Created March 21, 2020 19:14
Show Gist options
  • Save dan-dm/5140be28536846a3c662b6bd773366a3 to your computer and use it in GitHub Desktop.
Save dan-dm/5140be28536846a3c662b6bd773366a3 to your computer and use it in GitHub Desktop.
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.
/* 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. */
public class Problema_EULER_1{
public static void main (String[] args) {
int sum_3 = 0,
sum_5 = 0;
for (int x =1; x<=1000; x++) {
if ( (x*3) < 1000) {
sum_3 += (x*3);
}
if ( (x*5) < 1000 ) {
sum_5 += (x*5);
}
System.out.println((x*3) + " " + (x*5) + " " + sum_3 + " " + sum_5);
}
System.out.println(sum_3);
System.out.println(sum_5);
System.out.println(sum_3+sum_5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment