-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.php
More file actions
48 lines (41 loc) · 1.25 KB
/
Copy path5.php
File metadata and controls
48 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Smallest Multiple |
| 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? |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
$factors = array();
$primeFac = array(0 => 2);
function getFac($input) {
global $primeFac;
for($x = 3; $x < $input; $x += 2) {
$getFac = 1;
foreach((array)$primeFac as $prime) {
if($x % $prime == 0) {
$getFac = 0;
break;
}
}
if($getFac) {
$primeFac[] = $x;
}
}
if($getFac) return TRUE;
else return FALSE;
}
function smallestMultiple($input) {
global $primeFac;
$solution = 1;
getFac($input);
foreach((array)$primeFac as $prime) {
$pow = floor(log($input, $prime));
$solution = $solution*pow($prime, $pow);
}
echo $solution."\n";
}
smallestMultiple(20);
?>