gmp_gcdext

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

gmp_gcdextCalculate GCD and multipliers

Beschreibung

gmp_gcdext(GMP|int|string $num1, GMP|int|string $num2): array

Calculates g, s, and t, such that a*s + b*t = g = gcd(a,b), where gcd is the greatest common divisor. Returns an array with respective elements g, s and t.

This function can be used to solve linear Diophantine equations in two variables. These are equations that allow only integer solutions and have the form: a*x + b*y = c. For more information, go to the » "Diophantine Equation" page at MathWorld

Parameter-Liste

num1

Ein GMP-Object, ein Integer oder eine numeriche Zeichenkette.

num2

Ein GMP-Object, ein Integer oder eine numeriche Zeichenkette.

Rückgabewerte

An array of GMP numbers.

Beispiele

Beispiel #1 Solving a linear Diophantine equation

<?php
// Solve the equation a*s + b*t = g
// where a = 12, b = 21, g = gcd(12, 21) = 3
$a gmp_init(12);
$b gmp_init(21);
$g gmp_gcd($a$b);
$r gmp_gcdext($a$b);

$check_gcd = (gmp_strval($g) == gmp_strval($r['g']));
$eq_res gmp_add(gmp_mul($a$r['s']), gmp_mul($b$r['t']));
$check_res = (gmp_strval($g) == gmp_strval($eq_res));

if (
$check_gcd && $check_res) {
    
$fmt "Solution: %d*%d + %d*%d = %d\n";
    
printf($fmtgmp_strval($a), gmp_strval($r['s']), gmp_strval($b),
    
gmp_strval($r['t']), gmp_strval($r['g']));
} else {
    echo 
"Error while solving the equation\n";
}

// output: Solution: 12*2 + 21*-1 = 3
?>

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

在线购买中国护照(Telegram:@Globaldocs16)购买中国护照、身份证、驾驶证

在线购买中国护照(Telegram:@Globaldocs16)购买中国护照、身份证、驾驶证、绿卡、居留证、雅思成绩、工作证、公 ...

Geschrieben von toretovon76 am 16.06.2026 02:27:48
Forum: XML
Buy real and fake Passports (WhatsApp: +1 (615)-314-6286) renew passports

Buy real and fake Passports (WhatsApp: +1 (615)-314-6286) renew passports online, apply for legal passports, buy fake passports, Buy US passports, ...

Geschrieben von toretovon76 am 16.06.2026 02:26:40
Forum: XML
在线购买中国护照(Telegram:@Globaldocs16)购买中国护照、身份证、驾驶证、绿卡

在线购买中国护照(Telegram:@Globaldocs16)购买中国护照、身份证、驾驶证、绿卡、居留证、雅思成绩、工作证、公 ...

Geschrieben von toretovon76 am 16.06.2026 02:24:23
Forum: SQL / Datenbanken
Buy real and fake Passports (WhatsApp: +1 (615)-314-6286) renew passports

Buy real and fake Passports (WhatsApp: +1 (615)-314-6286) renew passports online, apply for legal passports, buy fake passports, Buy US passports, ...

Geschrieben von toretovon76 am 16.06.2026 02:23:45
Forum: SQL / Datenbanken