Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Mathematics and Algorithms > Mathematical Functions > Integer Functions >

GCD

GCD[n1, n2, ...]
gives the greatest common divisor of the ni.
  • Integer mathematical function, suitable for both symbolic and numerical manipulation.
  • GCD works with ordinary and Gaussian integers.
  • GCD works not only with integers but also rational numbers, both real and complex.
  • For rational numbers ri, GCD[r1, r2, ...] gives the greatest rational number r for which all the ri/r are integers.
  • GCD automatically threads over lists.
Greatest common divisor of three numbers:
Plot the GCD for a number with 1000:
Greatest common divisor of three numbers:
In[1]:=
Click for copyable input
Out[1]=
 
Plot the GCD for a number with 1000:
In[1]:=
Click for copyable input
Out[1]=
GCD threads element-wise over lists:
Use with rational arguments:
Use with Gaussian integers:
TraditionalForm formatting:
Find the fraction of pairs of the first 100 numbers that are relatively prime:
The result is close to 1/zeta(2):
Plot the means of the GCDs for successive "balls" of numbers:
Conditions for solvability of a linear congruence equation:
GCDs of Fibonacci numbers:
Use CoprimeQ to check for trivial GCDs:
Compute GCD from Floor:
Use in sums:
Simplify expressions containing GCD:
Reduce inequalities involving GCD:
GCD is very fast, even for many very large integers:
Signs are discarded:
The arguments must be explicit integers:
GCD sorts its arguments:
Plot the argument of the Fourier transform of the GCDs:
Form GCDs of 1 with rational numbers:
A GCD property of Fibonacci numbers:
New in 1 | Last modified in 4
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team