BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Znajduje największy wspólny dzielnika dwóch BigInteger wartości.
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
Parametry
- left
- BigInteger
Pierwsza wartość.
- right
- BigInteger
Druga wartość.
Zwraca
Największy wspólny dzielnika left i right.
Przykłady
W poniższym przykładzie przedstawiono wywołanie GreatestCommonDivisor metody i obsługę wyjątków niezbędną do dostarczenia przydatnych informacji o metodzie ArgumentOutOfRangeException. Wynik wskazuje, że największym wspólnym dzielnikiem tych dwóch liczb jest 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
Uwagi
Największy wspólny dzielnik to największa liczba, w której można podzielić dwie BigInteger wartości bez zwracania reszty.
left Jeśli parametry i right są liczbami niezerowymi, metoda zawsze zwraca wartość co najmniej 1, ponieważ wszystkie liczby mogą być podzielone przez 1. Jeśli którykolwiek parametr ma wartość zero, metoda zwraca wartość bezwzględną parametru innego niż zero. Jeśli obie wartości mają wartość zero, metoda zwraca zero.
Note
Obliczanie największego wspólnego dzielnika bardzo dużych wartości left i right może być bardzo czasochłonną operacją.
Wartość zwracana przez metodę GreatestCommonDivisor jest zawsze dodatnia (w tym zero), niezależnie od znaku parametrów left i right .