BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) Metoda

Definice

Najde největšího společného dělitele dvou BigInteger hodnot.

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

První hodnota.

right
BigInteger

Druhá hodnota.

Návraty

Největší společný dělitel left a right.

Příklady

Následující příklad znázorňuje volání GreatestCommonDivisor metody a zpracování výjimek nezbytné k poskytnutí užitečných informací o objektu ArgumentOutOfRangeException. Výsledek značí, že největší společný dělitel těchto dvou čísel je 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);
}
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

Poznámky

Největším společným dělitelem je největší číslo, na které lze tyto dvě BigInteger hodnoty rozdělit bez vrácení zbytku.

left Pokud jsou parametry a right nenulová čísla, vrátí metoda vždy alespoň hodnotu 1, protože všechna čísla lze dělit 1. Pokud je některý z parametrů nula, vrátí metoda absolutní hodnotu nenulového parametru. Pokud jsou obě hodnoty nula, vrátí metoda nulu.

Poznámka

Výpočet největšího společného dělitele velmi velkých hodnot left a right může být velmi časově náročná operace.

Hodnota vrácená metodou GreatestCommonDivisor je vždy kladná bez ohledu na znaménko left parametrů a right .

Platí pro