{ “title”: “GCD”, “language”: “en”, “description”: “Calculates the greatest common divisor (GCD) of two integers.” }

Description

Calculates the greatest common divisor (GCD) of two integers.

Syntax

GCD(<a>, <b>)

Parameters

ParameterDescription
<a>The first integer
<b>The second integer

Return Value

Returns the greatest common divisor of <a> and <b>. If any input is NULL, returns NULL.

Examples

select gcd(54, 24);
+------------+
| gcd(54,24) |
+------------+
|          6 |
+------------+
select gcd(-17, 31);
+--------------+
| gcd(-17,31)  |
+--------------+
|            1 |
+--------------+
select gcd(0, 10);
+-----------+
| gcd(0,10) |
+-----------+
|        10 |
+-----------+
select gcd(54, NULL);
+---------------+
| gcd(54, NULL) |
+---------------+
|          NULL |
+---------------+