BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) メソッド

定義

2 つの BigInteger 値の最大公約数を求めます。Finds the greatest common divisor of two BigInteger values.

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

最初の値。The first value.

right
BigInteger

秒の値。The second value.

戻り値

leftright の最大公約数。The greatest common divisor of left and right.

次の例は、GreatestCommonDivisor メソッドの呼び出しと、ArgumentOutOfRangeExceptionに関する有益な情報を提供するために必要な例外処理を示しています。The following example illustrates a call to the GreatestCommonDivisor method and the exception handling necessary to provide useful information about an ArgumentOutOfRangeException. 結果は、この2つの数値の最も一般的な除数が1であることを示します。The result indicates that the greatest common divisor of these two numbers is 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                           

注釈

最も一般的な除数は、剰余を返さずに2つの BigInteger 値を分割できる最大数です。The greatest common divisor is the largest number into which the two BigInteger values can be divided without returning a remainder.

left パラメーターと right パラメーターが0以外の数値の場合、すべての数値を1で割ることができるため、メソッドは常に少なくとも1の値を返します。If the left and right parameters are non-zero numbers, the method always returns at least a value of 1 because all numbers can be divided by 1. どちらかのパラメーターがゼロの場合、メソッドはゼロ以外のパラメーターの絶対値を返します。If either parameter is zero, the method returns the absolute value of the non-zero parameter. 両方の値が0の場合、メソッドは0を返します。If both values are zero, the method returns zero.

注意

leftright の非常に大きな値の最大公約数を計算すると、非常に時間がかかる操作になることがあります。Computing the greatest common divisor of very large values of left and right can be a very time-consuming operation.

GreatestCommonDivisor メソッドによって返される値は、leftright パラメーターの符号に関係なく、常に正になります。The value returned by the GreatestCommonDivisor method is always positive regardless of the sign of the left and right parameters.

適用対象