Project Euler Question
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?
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?
<?php
function code_solution_5() {
$prime_factors = [];
$start = 2;
$end = 20;
for($i = $start; $i<= $end; $i++) {
$prime_factors[$i] = get_prime_factors($i);
}
$prime_combined = [];
foreach($prime_factors as $prime_factor_array) {
foreach($prime_factor_array as $key => $value) {
$old_val = $prime_combined[$key] ?? 0;
$prime_combined[$key] = max([$old_val, $value]);
}
}
$product = 1;
foreach($prime_combined as $prime => $exponent) {
$product *= pow($prime, $exponent);
}
return $product;
}