BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Находит наибольший общий делитель двух BigInteger значений.
public:
static System::Numerics::BigInteger GreatestCommonDivisor(System::Numerics::BigInteger left, System::Numerics::BigInteger right);
public static System.Numerics.BigInteger GreatestCommonDivisor(System.Numerics.BigInteger left, System.Numerics.BigInteger right);
static member GreatestCommonDivisor : System.Numerics.BigInteger * System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Function GreatestCommonDivisor (left As BigInteger, right As BigInteger) As BigInteger
Параметры
- left
- BigInteger
Первое значение.
- right
- BigInteger
Второе значение.
Возвращаемое значение
Величайший общий делитель left и right.
Примеры
В следующем примере показан вызов GreatestCommonDivisor метода и обработка исключений, необходимых для предоставления полезных сведений о объекте ArgumentOutOfRangeException. Результат указывает на то, что наибольший общий делитель этих двух чисел равен 1.
BigInteger n1 = BigInteger.Pow(154382190, 3);
BigInteger n2 = BigInteger.Multiply(1643590, 166935);
try
{
Console.WriteLine("The greatest common divisor of {0} and {1} is {2}.",
n1, n2, BigInteger.GreatestCommonDivisor(n1, n2));
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("Unable to calculate the greatest common divisor:");
Console.WriteLine(" {0} is an invalid value for {1}",
e.ActualValue, e.ParamName);
}
let n1 = BigInteger.Pow(154382190, 3)
let n2 = BigInteger.Multiply(1643590, 166935)
try
printfn $"The greatest common divisor of {n1} and {n2} is {BigInteger.GreatestCommonDivisor(n1, n2)}."
with :? ArgumentOutOfRangeException as e ->
printfn $"Unable to calculate the greatest common divisor:"
printfn $" {e.ActualValue} is an invalid value for {e.ParamName}"
Dim n1 As BigInteger = BigInteger.Pow(154382190, 3)
Dim n2 As BigInteger = BigInteger.Multiply(1643590, 166935)
Try
Console.WriteLine("The greatest common divisor of {0} and {1} is {2}.", _
n1, n2, BigInteger.GreatestCommonDivisor(n1, n2))
Catch e As ArgumentOutOfRangeException
Console.WriteLine("Unable to calculate the greatest common divisor:")
Console.WriteLine(" {0} is an invalid value for {1}", _
e.ActualValue, e.ParamName)
End Try
Комментарии
Наибольший общий делитель — это наибольшее число, в которое можно разделить два BigInteger значения, не возвращая оставшуюся часть.
left Если и right параметры являются ненулевыми числами, метод всегда возвращает по крайней мере значение 1, так как все числа можно разделить на 1. Если любой параметр равен нулю, метод возвращает абсолютное значение ненулевого параметра. Если оба значения равны нулю, метод возвращает ноль.
Note
Вычисление наибольшего общего делителя очень больших значений left и right может быть очень трудоемкой операцией.
Возвращаемое методом GreatestCommonDivisor значение всегда положительно (включая ноль) независимо от знака left и right параметров.