GCD in LaTeX (\gcd(a, b))

gcd⁡(a,b)\gcd(a, b)
LaTeX command
\gcd(a, b)
Package
No package needed: built into LaTeX
Mode
Math mode only

Where it is used

Greatest common divisor of a and b, the largest integer dividing both.

\gcd is a predefined operator, so it prints upright, and like \lim it accepts limits under it in display style. Bezout's identity says \gcd(a, b) = ax + by for some integers x and y, and a and b are coprime when \gcd(a, b) = 1. Many number theory papers drop the name and write (a, b), which is compact but clashes with ordered pairs and open intervals. The Euclidean algorithm rests on \gcd(a, b) = \gcd(b, a \bmod b), where \bmod gives binary-operator spacing. There is no matching built-in command for the least common multiple.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a, b) = \gcd(b, a \bmod b)
\documentclass{article}
\begin{document}
GCD: $\gcd(a, b)$

\[ \gcd(a, b) = \gcd(b, a \bmod b) \]
\end{document}

Related symbols

All Teori Bilangan →

Frequently asked questions

How do I write GCD in LaTeX?
Type \gcd(a, b) in math mode, for example $\gcd(a, b) = \gcd(b, a \bmod b)$. It works in plain LaTeX without loading any package.
Which package do I need for \gcd(a, b)?
None. \gcd(a, b) is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use \gcd(a, b) in text mode, or only in math mode?
Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\gcd(a, b)$ in running text.
Math poweredTulis LaTeX menggunakan AI

Editor LaTeX AI Terbaik, Alternatif Overleaf

Octree membantu peneliti dari 15+ universitas menulis makalah penelitian lebih cepat menggunakan AI

  • Hasilkan diagram TikZ yang indah menggunakan AI
  • Unggah gambar dan konversi ke LaTeX dengan mulus
  • Dapatkan bantuan instan untuk menulis dan memformat makalah penelitian