BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Busca el divisor más común de dos BigInteger valores.
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
Parámetros
- left
- BigInteger
Primer valor.
- right
- BigInteger
Segundo valor.
Devoluciones
El mayor divisor común de left y right.
Ejemplos
En el GreatestCommonDivisor ejemplo siguiente se muestra una llamada al método y el control de excepciones necesario para proporcionar información útil sobre .ArgumentOutOfRangeException El resultado indica que el divisor más común de estos dos números es 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);
}
let n1 = BigInteger.Pow(154382190, 3)
let n2 = BigInteger.Multiply(1643590, 166935)
try
printfn $"The greatest common divisor of {n1} and {n2} is {BigInteger.GreatestCommonDivisor(n1, n2)}."
with :? ArgumentOutOfRangeException as e ->
printfn $"Unable to calculate the greatest common divisor:"
printfn $" {e.ActualValue} is an invalid value for {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
Comentarios
El divisor más común es el número más grande en el que se pueden dividir los dos BigInteger valores sin devolver un resto.
Si los left parámetros y right son números distintos de cero, el método siempre devuelve al menos un valor de 1 porque todos los números se pueden dividir por 1. Si cualquiera de los parámetros es cero, el método devuelve el valor absoluto del parámetro distinto de cero. Si ambos valores son cero, el método devuelve cero.
Note
Calcular el mayor divisor común de valores muy grandes de left y right puede ser una operación muy lenta.
El valor devuelto por el GreatestCommonDivisor método siempre es positivo (incluido cero) independientemente del signo de los left parámetros y right .