PHP | gmp_gcdext() function Last Updated : 14 Jun, 2018 Comments Improve Suggest changes Like Article Like Report The gmp_gcdext() is an inbuilt function in PHP which calculates the GCD ( Greatest Common Divisor ) and multipliers of a given equation such that a * x + b * y = GCD(a, b), where GCD is the greatest common divisor. This function is used to solve linear Diophantine equation in two variables . Syntax: array gmp_gcdext ( GMP $a, GMP $b ) Parameters: The gmp_gcdext() function accepts two parameters as listed above and described below: $a: This parameter can be a GMP resource in PHP 5.5 and earlier, a GMP object in PHP 5.6, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number. $b: This parameter can be a GMP resource in PHP 5.5 and earlier, a GMP object in PHP 5.6, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number. Return Values: This function will return an array of GMP numbers (GNU Multiple Precision: For large numbers) that is the multipliers (x and y of a given equation ) and the gcd. Examples: Input: a = 12 , b = 21 equation = 12 * x + 21 * y = 3 Output: Input: a = 5 , b = 10 equation = 5 * x + 10 * y = 5 Output: x = 1 , y = 0 , GCD(12,21) = 5 Below program illustrate the gmp_gcdext() function: php <?php // PHP code to solve a Diophantine equation // Solve the equation a*x + b*y = g // where a =, b =, g = gcd(5, 6) = 1 $a = gmp_init(5); $b = gmp_init(6); // calculates gcd of two gmp numbers $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($fmt, gmp_strval($a), gmp_strval($r['s']), gmp_strval($b), gmp_strval($r['t']), gmp_strval($r['g'])); } else echo "Error generated\n"; ?> Output: Solution: 5 * -1 + 6 * 1 = 1 Reference : http://php.net/manual/en/function.gmp-gcdext.php Comment More infoAdvertise with us Next Article PHP | gmp_gcdext() function P priya_1998 Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-gmp Similar Reads PHP | gmp_gcd() Function The gmp_gcd() is an in built function in PHP which is used to calculate the GCD of 2 GMP numbers (GNU Multiple Precision : For large numbers). Syntax: gmp_gcd ( $num1, $num2 ) Parameters: This function accepts two GMP numbers $num1 and $num2 as parameters. This function calculates the GCD of these t 1 min read PHP | gmp_or() Function The gmp_or() is an inbuilt function in PHP which is used to calculate the bitwise OR of two GMP numbers(GNU Multiple Precision : For large numbers). Syntax: gmp_or($num1, $num2) Parameters: This function accepts two GMP numbers, $num1, $num2 as mandatory parameters as shown in the above syntax. Thes 2 min read PHP | gmdate() Function The gmdate() is an inbuilt function in PHP which is used to format a GMT/UTC date and time and return the formatted date strings. It is similar to the date() function but it returns the time in Greenwich Mean Time (GMT). Syntax: string gmdate ( $format, $timestamp ) Parameters: The gmdate() function 2 min read PHP | Gmagick getsize() Function The Gmagick::getsize() function is an inbuilt function in PHP which is used to get the size associated with the Gmagick object. Syntax: array Gmagick::getsize( void ) Parameters: This function doesnât accept any parameter. Return Value: This function returns an associative array containing the keys 1 min read PHP | gmp_com() Function The gmp_com() is an inbuilt function in PHP which is used to calculate the one's complement of a GMP number(GNU Multiple Precision : For large numbers). Syntax: gmp_com($num) Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax. This parameter can 2 min read PHP | gmp_cmp() Function The gmp_cmp() is an inbuilt function in PHP which is used to compare two GMP numbers(GNU Multiple Precision : For large numbers). Syntax: gmp_cmp($num1, $num2) Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters as shown in the above syntax for comparing. These 2 min read PHP | gmp_xor() Function The gmp_xor() is an in-built function in PHP which is used to calculate the XOR of 2 GMP numbers (GNU Multiple Precision : For large numbers). Syntax: gmp_xor( $num1, $num2 ) Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters shown in the above syntax. These pa 2 min read PHP | gmp_mul() Function The gmp_mul() function in PHP is an inbuilt function which is used to multiply two GMP numbers (GNU Multiple Precision: For large numbers). Syntax: GMP gmp_mul ( GMP $num1, GMP $num2 ) Parameters: This function accepts two GMP numbers. It is mandatory parameters as shown in the above syntax. These c 1 min read PHP | gmp_neg() Function The gmp_neg() function is an in-built function in PHP which returns the negative of a GMP number (GNU Multiple Precision). Syntax : gmp_neg( $num ) Parameters : The function accepts only one mandatory parameter $num which can be either a GMP number resource in PHP 5.5 or a GMP object in PHP version 1 min read PHP | gmp_pow() Function The gmp_pow() is an inbuilt function in PHP which is used to calculate the power raised to a number of a GMP number and an integer (GNU Multiple Precision: For large numbers). Syntax: gmp_pow( $base, $exp ) Parameters: The function accepts two mandatory parameters $base and $exp. $base - It is the b 2 min read Like