-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseEuclid.php
More file actions
49 lines (41 loc) · 925 Bytes
/
UseEuclid.php
File metadata and controls
49 lines (41 loc) · 925 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
40
41
42
43
44
45
46
47
48
49
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Macocci7\PhpMathInteger\Euclid;
// Presets values
$e = new Euclid();
$a = 390;
$b = 273;
$c = 39;
// Judges if $c is GCD($a, $b) or not
echo sprintf(
"Is %d GCD(%d, %d)? - %s.\n",
$c,
$a,
$b,
$e->isGcdOf($c, $a, $b) ? 'Yes' : 'No'
);
// Euclidean Algorithm
$r = $e->run($a, $b);
echo "Euclidean Algorithm:\n";
foreach ($r['processText'] as $t) {
echo $t . "\n";
}
// Formula of remainders
echo "Remainders can be expressed as:\n";
foreach ($r['processData'] as $d) {
echo sprintf("%d = %d - %d * %d\n", $d['r'], $d['a'], $d['b'], $d['c']);
}
// Judges if $a and $b are coprime or not
echo sprintf(
"Are %d and %d coprime? - %s.\n",
$a,
$b,
$e->isCoprime($a, $b) ? 'Yes' : 'No'
);
// GCD($a, $b)
echo sprintf(
"Because the Greatest Common Divisor of %d and %d is %d.\n",
$a,
$b,
$e->gcd($a, $b)
);