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

두 번째 값입니다.

반환

BigInteger

leftright의 최대 공약수입니다.

예제

다음 예제에서는 메서드 호출 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);
}
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 값을 나눌 수 있는 가장 큰 수입니다.

right 매개 변수가 left 0이 아닌 숫자인 경우 모든 숫자를 1로 나눌 수 있으므로 메서드는 항상 1 이상의 값을 반환합니다. 두 매개 변수 중 하나가 0이면 메서드는 0이 아닌 매개 변수의 절대값을 반환합니다. 두 값이 모두 0이면 메서드는 0을 반환합니다.

참고

매우 큰 값의 left 가장 큰 공통 수수를 계산하는 right 것은 매우 시간이 많이 걸리는 작업일 수 있습니다.

메서드에서 반환되는 GreatestCommonDivisor 값은 부호 leftright 매개 변수에 관계없이 항상 양수입니다.

적용 대상