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

定義

2 つの 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

2 番目の値。

戻り値

BigInteger

leftright の最大公約数。

次の例は、メソッドの GreatestCommonDivisor 呼び出しと、 ArgumentOutOfRangeException. 結果は、これら 2 つの数値の最大の共通除数が 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 値を分割できる最大の数値です。

leftパラメーターとrightパラメーターが 0 以外の数値の場合、すべての数値を 1 で除算できるため、メソッドは常に少なくとも 1 の値を返します。 いずれかのパラメーターが 0 の場合、メソッドは 0 以外のパラメーターの絶対値を返します。 両方の値が 0 の場合、メソッドは 0 を返します。

注意

非常に大きな値の最も一般的な除数を left 計算すると、 right 非常に時間のかかる操作になる可能性があります。

メソッドによってGreatestCommonDivisor返される値は、and right パラメーターの符号に関係なく常にleft正です。

適用対象