# gmp_gcdext

(PHP 4 >= 4.0.4, PHP 5)

gmp_gcdextCalculate GCD and multipliers

### 说明

array gmp_gcdext ( resource \$a , resource \$b )

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

a

b

### 返回值

An array of GMP numbers.

### 范例

Example #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 ";    printf(\$fmt, gmp_strval(\$a), gmp_strval(\$r['s']), gmp_strval(\$b),    gmp_strval(\$r['t']), gmp_strval(\$r['g']));} else {    echo "Error while solving the equation ";}// output: Solution: 12*2 + 21*-1 = 3?> ```

• gmp_abs
• gmp_and
• gmp_clrbit
• gmp_cmp
• gmp_div
• gmp_divexact
• gmp_div_q
• gmp_div_qr
• gmp_div_r
• gmp_fact
• gmp_gcd
• gmp_gcdext
• gmp_hamdist
• gmp_init
• gmp_intval
• gmp_invert
• gmp_jacobi
• gmp_legendre
• gmp_mod
• gmp_mul
• gmp_neg
• gmp_nextprime
• gmp_or
• gmp_perfect_square
• gmp_popcount
• gmp_pow
• gmp_powm
• gmp_prob_prime
• gmp_random
• gmp_scan0
• gmp_scan1
• gmp_setbit
• gmp_sign
• gmp_sqrt
• gmp_sqrtrem
• gmp_strval
• gmp_sub
• gmp_testbit
• gmp_xor
• PHP MySQL HTML CSS JavaScript MSSQL AJAX .NET JSP Linux Mac ASP 服务器 SQL jQuery C# C++ java Android IOS oracle MongoDB SQLite wamp 交通频道