Что такое код gmp_gcdext

Содержание

gmp_gcdext

(PHP 4 >= 4.0.4, PHP 5)

gmp_gcdext � Calculate GCD and multipliers

��������

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

������ ����������

����� ���� ��� ������ GMP, ��� �������, �������� ��, ��� �� �������� ��������� �������������� � �����.

����� ���� ��� ������ GMP, ��� �������, �������� ��, ��� �� �������� ��������� �������������� � �����.

������������ ��������

An array of GMP numbers.

�������

������ #1 Solving a linear Diophantine equation

// 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 ( $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\n» ;
>

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

��� ����� ��� gmp_gcdext

(PHP 4 >= 4.0.4, PHP 5)

gmp_gcdext — Calculate GCD and multipliers

Description 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

Пример 1. Solving a linear Diophantine equation

// 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 ( $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\n» ;
>

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

Илон Маск рекомендует:  Что такое код dba_fetch

The extended GCD can be used to calculate mutual modular inverses of two
coprime numbers. Internally gmp_invert uses this extended GCD routine,
but effectively throws away one of the inverses.

��� ����� ��� gmp_gcdext

(PHP 4 >= 4.0.4, PHP 5)

gmp_gcdext — Calculate GCD and multipliers

Description 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

������ 1. Solving a linear Diophantine equation

// 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 ( $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\n» ;
>

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

����. ������ ����.
gmp_gcd ������� ���� gmp_hamdist

���� �� �� ����� ��� ������, �� ���������� ��������������� ������� �� �����:

FPublisher

Web-����������: ���� ������

������������ PHP

��������� �����������:

���������� �� �����

��������� 14 ����� 2020 ����

�p���� Genesis (�� ��p��p������� ��p������)

��������� �� ������ � Vim

��������� 05 ������� 2020 ����

Vim �������� ������ ��������, �� ������ � ��� �� ������ ��������.
�������� ���� ����� ��������������� �����-�� ���� �������� ��� ������ crontab, ��� ������ ��������� ������ � viv �����.

������: Error: Cannot find a val >��������� 13 �������� 2020 ����

���� ��������� ������ �� centos 5 ����
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/

Linux Optimization

��������� 30 ���� 2012 ����

Linux.yaroslavl.ru

������� ���
����� �����

gmp_gcdext — ��������� GCD � ���������.

��������

array gmp_gcdext (resource a, resource b)

��������� g, s � t ���, ��� a*s + b*t = g = gcd(a,b) , ��� gcd �������� ���������� ����� ���������. ���������� ������ � ���������������� ���������� g, s � t.

gmp_gcdext

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

gmp_gcdext � Calculate GCD and multipliers

Description

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

Parameters

Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number.

Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number.

Return Values

An array of GMP numbers.

Examples

Example #1 Solving a linear Diophantine equation

// 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 ( $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\n» ;
>

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

User Contributed Notes

The extended GCD can be used to calculate mutual modular inverses of two
coprime numbers. Internally gmp_invert uses this extended GCD routine,
but effectively throws away one of the inverses.

gmp_gcdext

(PHP 4 >= 4.0.4, PHP 5)

gmp_gcdext � Calculate GCD and multipliers

Description

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

Parameters

It can be either a GMP number resource, or a numeric string given that it is possible to convert the latter to a number.

It can be either a GMP number resource, or a numeric string given that it is possible to convert the latter to a number.

Return Values

An array of GMP numbers.

Examples

Example #1 Solving a linear Diophantine equation

// 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 ( $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\n» ;
>

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

gmp_gcdext

Calculate GCD and multipliers

Description

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

Parameters

It can be either a GMP number resource , or a numeric string given that it is possible to convert the latter to a number.

It can be either a GMP number resource , or a numeric string given that it is possible to convert the latter to a number.

Return Values

An array of GMP numbers.

Examples

Example #1 Solving a linear Diophantine equation

// 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 ( $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\n» ;
>

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

���������� �� PHP : ������� ������ � ������� : �������������� ������� : ������� GMP : ����������

�������� �� WebWikiABCD

����������

gmp_fact

���������� ��������� �����, ��������� � ��������� x.

gmp_sqrt

��������� ���������� ������.

���������� ���������� ������ �����, ��������� � ��������� x.

gmp_sqrtrm

��������� ���������� ������ � ��������.

������ ������� ���������� ������, � ������� ������� � �������� [0] — ��� ���������� ������ ���������, ������� � �������� [1] — �������� ����� ���������� � ��������� [0] � ��������.

gmp_perfect_square

����������, �������� �� ����� ������ ���������.

������� gmp_perfect_square() ��������� true, ���� x �������� ��������� ������ �����. � ��������� ������ ������ false.

gmp_pow

���������� � �������.

��� ������� ���������� ���������, ������ ���������� ��������� x � ������� y, ��� �������, ��� y �� �������������.

gmp_powm

gmp_prob_prime

�������� «��������» �������� �����.

��� ������� ��������� 0, � ������ ���� x ������� �����, �.�. ������� ����� ���� ����� ���������. ��������� 1, ���� x, ��������, ������� �����. ���� ���������� 2, �� ����� x — ��������� ������� �����.

�������� reps ���������� �������� ��������. ��� ������� ��� �����, ��� ������ ���������. ����� ��������� �������� �� 5 �� 10 (�� ���������).

��� ������� ���������� �������� �������������� ����� �������-������.

gmp_gcd

������� ���������� ����� ��������.

������ ���������� ������������� ���������.

gmp_gcdext

���������� ����������� ������ �������� �� �����������.

������� gmp_gcdext() ���������� ������ �� ���������� g,s,t, ������, ��� x*s+y*t=g=���(x,y), ��� ��� — ���������� ����� ��������.

gmp_invert

���������� �������� �� ������.

������� ���������� ���������� x �� ��������, ���������� ������ �� y. � ������, ���� ��������� �� ����� ���� ������, ���������� false.

gmp_legendre

���������� ����� ��������.

������� ���������� ����� ��������. p ������ ���� ������ �������������.

gmp_jacobi

���������� ����� �����.

������� ���������� ����� �����. p ������ ���� ������ �������������.

gmp_random

���������� ��������� ���������� �����.

limited ������ ����� ������������� �����. � ������, ���� �������� limited ������������, ������������ ������������� �����.

gmp_popcount

������� ���������� ��������� ���������.

gmp_hamdist

������� ���������� ��������� ����� ������� xy. ��������� xy ������ ���� ����������������.

PHP | gmp_gcdext() function

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:

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:

Below program illustrate the gmp_gcdext() function:

Илон Маск рекомендует:  Что такое код dotnet_load
Понравилась статья? Поделиться с друзьями:
Кодинг, CSS и SQL