Share via


BigInteger.GreatestCommonDivisor Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Finds the greatest common divisor of two BigInteger values.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

Syntax

'Declaration
Public Shared Function GreatestCommonDivisor ( _
    left As BigInteger, _
    right As BigInteger _
) As BigInteger
public static BigInteger GreatestCommonDivisor(
    BigInteger left,
    BigInteger right
)

Parameters

Return Value

Type: System.Numerics.BigInteger
The greatest common divisor of left and right.

Remarks

The greatest common divisor is the largest number into which the two BigInteger values can be divided without returning a remainder.

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. If both values are zero, the method returns zero.

NoteNote:

Computing the greatest common divisor of very large values of left and right can be a very time-consuming operation.

The value returned by the GreatestCommonDivisor method is always positive regardless of the sign of the left and right parameters.

Examples

The following example illustrates a call to the GreatestCommonDivisor method and the exception handling necessary to provide useful information about an ArgumentOutOfRangeException. The result indicates that the greatest common divisor of these two numbers is 1.

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.