GCD in LaTeX (\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.
\documentclass{article}
\begin{document}
GCD: $\gcd(a, b)$
\[ \gcd(a, b) = \gcd(b, a \bmod b) \]
\end{document}Related symbols
- LCM
\text{lcm}(a, b) - Does Not Divide
\nmid - Equivalent
\equiv - Conditional
\mid - Modulo
\pmod{n} - Euler Phi
\varphi(n)
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.
Pinakamahusay na AI LaTeX Editor, Alternatibo sa Overleaf
Tinutulungan ng Octree ang mga researcher mula sa 15+ na unibersidad na sumulat ng research papers nang mas mabilis gamit ang AI
- Gumawa ng magagandang TikZ diagrams gamit ang AI
- Mag-upload ng larawan at i-convert ito sa LaTeX nang walang problema
- Makakuha ng instant na tulong sa pagsulat at pag-format ng research papers