Euler 005 javascript Solution

Smallest multiple

Problem

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?

Answer: 232792560

Solution

solution005.js

module.exports = {
  answer : () => {
    var answer = 0;
    var test = 20;
    var check = false;

    while( !check ) {
      check = true;
      for( i = 20 ; i && check ; --i ) {
        check &= (0 == (test % i));
      }
      if( !check ) {
        test += 20;
      }
    }
    return test;
  }
};

See Also

# cpp go java php ruby rust javascript
1
2
3  
4    
5    
6      
7          
8          
9          
10          
11          
12          
# cpp ruby
13
14
15
16
17
18
19
20  
21  
22  
23  
24