-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseDivisor.php
More file actions
39 lines (31 loc) · 904 Bytes
/
UseDivisor.php
File metadata and controls
39 lines (31 loc) · 904 Bytes
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
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Macocci7\PhpMathInteger\Divisor;
$d = new Divisor();
$a = 12;
$b = 18;
// Number of divisors
echo sprintf("%d has %d divisors.\n", $a, $d->count($a));
// List of all divisors
echo sprintf("[%s]\n", implode(', ', $d->list($a)));
// Common factors
echo sprintf("%d = %s\n", $a, $d->formula($a));
echo sprintf("%d = %s\n", $b, $d->formula($b));
echo sprintf(
"common factors : %s\n",
$d->formula($d->value($d->commonFactors($a, $b)))
);
echo sprintf(
"common divisors : [%s]\n",
implode(', ', $d->commonDivisors($a, $b))
);
// greatest common factor (divisor)
echo sprintf(
"greatest common factor (divisor) : %s\n",
$d->greatestCommonFactor($a, $b)
);
// Reducing fraction
$r = $d->reduceFraction($a, $b);
$ra = $d->value($r[0]);
$rb = $d->value($r[1]);
echo sprintf("%d/%d reduces to %d/%d\n", $a, $b, $ra, $rb);