Project Euler Problem 5 (PHP)

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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?

Script

Execution Time: 19.8054 seconds

$stop = false;

for($x=20; $stop == false; $x=$x+20) {
    for ($y=2; $y<=19; $y++) {
        if($x%$y == 0) {
            $stop = true;
        } else {
            $stop = false;
            $y = 21;
        }
    }
    if ($stop == true) {
        echo $x.PHP_EOL;
    }
}

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
This entry was posted in PHP, Programming, Project Euler and tagged , , , . Bookmark the permalink.

Comments are closed.