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.
Math poweredAI로 LaTeX 작성
최고의 AI LaTeX 편집기, Overleaf 대안
Octree는 15개 이상의 대학의 연구자들이 AI를 사용하여 논문을 더 빠르게 작성하도록 도움
- AI로 아름다운 TikZ 다이어그램 생성
- 이미지를 업로드하고 LaTeX로 원활하게 변환
- 논문 작성 및 서식에 대한 즉각적인 지원 받기