This site is supported by donations to The OEIS Foundation.

# Template:GCD

(Redirected from Template:Gcd)

This template is under construction.

Please do not use this unfinished and/or still unreliable template.

This template employs intricate features of template syntax.

You are encouraged to familiarize yourself with its setup and parser functions before editing the template. If your edit causes unexpected problems, please undo it quickly, as this template may appear on a large number of pages.

The {{GCD}} mathematical function template returns the greatest common divisor (GCD) of one or two integers, as a nonnegative integer, unless the templates/parser functions nesting limit (depending on the configuration settings of the MediaWiki server) is exceeded by the Euclidean algorithm, in which case an error message is returned.

${\displaystyle \scriptstyle \gcd(0),\,\gcd(0,\,0),\,\gcd(0,\,0,\,0),\,\dots }$ are generally defined as 0. Essentially 0 acts as the top element (${\displaystyle \top }$ or ${\displaystyle \infty }$) in this and other contexts.[1][2][3]

Currently, the OEIS Wiki server seems to be configured to limit the number of nested template transclusions to 14 (which gives a limit of 13 iterations of the Euclidean algorithm, the {{GCD}} shell function doing only data validation and preparation for the {{~GCD}} core function, which implements the 0 th iteration of the Euclidean algorithm).

## Usage

{{GCD|an integer|an integer}}

or

{{gcd|an integer|an integer}}

or

{{GCD|an integer}}

or

{{gcd|an integer}}

## Valid input

One or two integers as arguments.

## Examples

Examples with valid input (returns GCD, unless the 10 iterations limit of the Euclidean algorithm is exceeded, where 0 is returned)

code result
{{GCD|0}} 0
{{GCD|0|0}} 0
{{GCD|1}} 1
{{GCD|6}} 6
{{GCD|0|6}} 6
{{GCD|6|0}} 6
{{GCD|16|6}} 2
{{GCD|16|32}} 16
{{GCD|25|625}} 25
{{GCD|544|119}} 17
{{GCD|119|544}} 17
{{GCD|-544|119}} 17
{{GCD|544|-119}} 17
{{GCD|-544|-119}} 17
{{GCD|2089|3571}} 1
{{GCD|3571|2089}} 1
{{GCD|{{Fibonacci|12}}|{{Fibonacci|11}}}} = {{GCD|144|89}} 1
{{GCD|{{Fibonacci|13}}|{{Fibonacci|12}}}} = {{GCD|233|144}} 1
{{GCD|{{Fibonacci|14}}|{{Fibonacci|13}}}} = {{GCD|377|233}} Expression error: Unexpected < operator.
{{GCD|{{Fibonacci|15}}|{{Fibonacci|14}}}} = {{GCD|610|377}} Expression error: Unexpected < operator.
{{GCD|{{Fibonacci|16}}|{{Fibonacci|15}}}} = {{GCD|987|610}} Expression error: Unexpected < operator.
{{GCD|{{Fibonacci|17}}|{{Fibonacci|16}}}} = {{GCD|1597|987}} Expression error: Unexpected < operator.
{{GCD|{{Fibonacci|18}}|{{Fibonacci|17}}}} = {{GCD|2584|1597}} Expression error: Unexpected < operator.
{{GCD|{{Fibonacci|19}}|{{Fibonacci|18}}}} = {{GCD|4181|2584}} Expression error: Unexpected < operator.
{{GCD|{{Fibonacci|20}}|{{Fibonacci|19}}}} = {{GCD|6765|4181}} Expression error: Unexpected < operator.
{{GCD|20891|35713}} 1
{{GCD|{{expr|2*3*5*7*11*13*17*19}}|{{expr|7*17*101*113}}}} 119
{{mpf|{{GCD|{{expr|2*3*5*7*11*13*17*19}}|{{expr|7*17*101*113}}}}}} Prime factors (with multiplicity) error: Argument must be a nonzero integer

Examples with invalid input (returns an error message)

code result
{{GCD}} GCD error: One or two integers as arguments are required.
{{GCD|ten|fifteen}} GCD error: One or two integers as arguments are required.
{{GCD|6.74|9}} GCD error: One or two integers as arguments are required.
{{GCD|2/3|4/9}} GCD error: One or two integers as arguments are required.