BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) Yöntem

Tanım

İki BigInteger değerin en büyük ortak bölenini bulur.

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

Parametreler

left
BigInteger

İlk değer.

right
BigInteger

İkinci değer.

Döndürülenler

ve'nin righten büyük ortak bölenileft.

Örnekler

Aşağıdaki örnekte yöntemine GreatestCommonDivisor yapılan çağrı ve hakkında yararlı bilgiler sağlamak için gereken özel durum işleme gösterilmektedir ArgumentOutOfRangeException. Sonuç, bu iki sayının en büyük ortak bölenin 1 olduğunu gösterir.

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

Açıklamalar

En büyük ortak bölen, kalan bir değer döndürmeden iki BigInteger değerin bölünebileceği en büyük sayıdır.

left ve right parametreleri sıfır olmayan sayılarsa, tüm sayılar 1'e bölünebileceğinden yöntem her zaman en az 1 değerini döndürür. Parametrelerden biri sıfırsa, yöntem sıfır olmayan parametrenin mutlak değerini döndürür. Her iki değer de sıfırsa, yöntem sıfır döndürür.

Not

ve değerlerinin en büyük ortak böleni leftright hesaplama çok zaman alan bir işlem olabilir.

yöntemi tarafından GreatestCommonDivisor döndürülen değer, ve right parametrelerinin işaretinden left bağımsız olarak her zaman pozitiftir.

Şunlara uygulanır