Project Euler – Problem 5 Solution
Hello! Problem 5 from Project Euler is a great problem that tests both mathematical thinking and programming skills. In this article, we'll find the smallest positive number that is divisible by all numbers from 1 to 20.
Problem Definition
The problem states that the smallest number that is divisible by all numbers from 1 to 10 is 2520. We ask, From 1 to 20 We are asked to find the smallest positive number that is divisible by all numbers.
* https://projecteuler.net/problem=5
Php;
<?php
$number = 20;
$isFound = false;
$checkList = [11, 13, 14, 16, 17, 18, 19, 20];
while (!$isFound) {
$divided = true;
foreach ($checkList as $check) {
if ($number % $check != 0) {
$divided = false;
break;
}
}
if ($divided) {
$isFound = true;
echo "Number is $number";
break;
} else {
$number+=20;
}
}
Javascript;
'use strict'; var number = 20; var isFound = false; var checkList = [11, 13, 14, 16, 17, 18, 19, 20]; while (!isFound) { var divided = true; for (let check of checkList) { if (number % check != 0) { divided = false; break; } } if (divided) { isFound = true; console.log("Number is " + number); break; } else { number+=20; } }

