Programming Language: Golang

Namespace/Package Name: math/big

Class/Type: Int

Method/Function: GCD

Examples at hotexamples.com: 19

The math/big package library in Go provides support for arbitrary precision arithmetic. The GCD function computes the greatest common divisor of two integers represented as big.Int.

**Example 1:** Compute GCD of two numbers

**Example 2:** Compute GCD of multiple numbers

import ( "fmt" "math/big" ) func main() { a := big.NewInt(12) b := big.NewInt(18) gcd := new(big.Int).GCD(nil, nil, a, b) fmt.Println(gcd) // Output: 6 }

import ( "fmt" "math/big" ) func main() { numbers := []*big.Int{big.NewInt(5), big.NewInt(10), big.NewInt(15), big.NewInt(20)} gcd := numbers[0] for i := 1; i < len(numbers); i++ { gcd = new(big.Int).GCD(nil, nil, gcd, numbers[i]) } fmt.Println(gcd) // Output: 5 }Package library: Math/Big.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related