Wednesday, September 10, 2014

Even Multiple Challenge

Yet another challenge from http://projecteuler.net



https://projecteuler.net/problem=5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?



int sum = 0;

for (int i = 1; i < 1000; i++) {
    if ( i % 5 == 0 || i % 3 == 0) {
        sum += i;
    }    
}
System.out.println(sum);

No comments:

Post a Comment