BigInteger.GreatestCommonDivisor(BigInteger, BigInteger) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Trouve le plus grand diviseur commun de deux BigInteger valeurs.
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
Paramètres
- left
- BigInteger
Première valeur.
- right
- BigInteger
Deuxième valeur.
Retours
Le plus grand diviseur commun de left et right.
Exemples
L’exemple suivant illustre un appel à la GreatestCommonDivisor méthode et la gestion des exceptions nécessaires pour fournir des informations utiles sur un ArgumentOutOfRangeException. Le résultat indique que le plus grand diviseur commun de ces deux nombres est 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
Remarques
Le plus grand diviseur commun est le plus grand nombre dans lequel les deux BigInteger valeurs peuvent être divisées sans retourner un reste.
Si les left valeurs et right paramètres ne sont pas zéro, la méthode retourne toujours au moins une valeur de 1, car tous les nombres peuvent être divisés par 1. Si l’un ou l’autre paramètre est égal à zéro, la méthode retourne la valeur absolue du paramètre autre que zéro. Si les deux valeurs sont égales à zéro, la méthode retourne zéro.
Note
Le calcul du plus grand diviseur commun de très grandes valeurs de left et right peut être une opération très fastidieuse.
La valeur retournée par la GreatestCommonDivisor méthode est toujours positive (y compris zéro), quel que soit le signe des paramètres et right des left paramètres.