Diophantine Equation - from Wikipedia
Euclidean algorithm - From Wikipedia
Euclid's Algorithm to find GCD of two Numbers
<?php
array gmp_gcdext ( GMP|int|string $num1,
GMP|int|string $num2 )
where,
$num1 = The first value to get the GCD and mutipliers
$num2 = The second value to get the GCD and mutipliers
?>
<?php
$a = 0;
$b = 11;
// You must try other values
$obj01 = gmp_gcdext($a, $b);
print_r($obj01);
$g = gmp_strval($obj01['g']);
$s = gmp_strval($obj01['s']);
$t = gmp_strval($obj01['t']);
echo '$a = ' . $a . '<br><br>';
echo '$b = ' . $b . '<br><br><br>';
echo '$g = '. $g . '<br><br>';
echo '$s = '. $s . '<br><br>';
echo '$t = '. $t . '<br><br><br>Where:<br><br>';
echo '$g = gmp_gcd( ' . $a . ', ' . $b . ' ) = ' .
gmp_gcd($a, $b) . '<br><br>';
$as = $a*$s;
$bt = $b*$t;
$abst = $as + $bt;
echo '$g = ( ' . $a . '*' . $s . '+' . $b .' *' . $t . ' ) = ' . $abst . '<br>';
?>
<?php
$n = gmp_init("34293864345");
$n1 = gmp_init("23434293864345");
$a = array(
array(123,45),
array(4341,9734),
array(23487,333),
array(-234234,-123123),
array(-100,-2234),
array(345,"34587345"),
array(345,"0"),
array("345556456",345873),
array("34545345556456","323432445873"),
array($n, $n1),
);
foreach ($a as $val) {
$r = gmp_gcdext($val[0],$val[1]);
$check = gmp_add(gmp_mul($val[0],$r['s']),
gmp_mul($val[1],$r['t']));
echo "\$r['s'] = " . $r['s'] . "<br>\$r['t'] = " .
$r['t'] . "<br>\$r['g'] = " . $r['g'] . '<br>where<br>';
echo "\$val[0] = $val[0]<br>\$val[1] = $val[1]<br>";
echo '$r[\'g\'] = ' . $val[0] . ' * ' . $r['s'] . ' + ' .
$val[1] . ' * ' . $r['t'] . ' = ' . ( $val[0] * $r['s'] +
$val[1] * $r['t'] ) . '<br><br>';
}
try {
var_dump(gmp_gcdext($val[0], array()));
echo '<br>';
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
try {
var_dump(gmp_gcdext(array(), array()));
echo '<br>';
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
?>