Difference between revisions of "Greatest common divisor"

From Free Pascal wiki
Jump to navigationJump to search
m
m
Line 1: Line 1:
{{Greatest common divisor}}
 
 
 
 
The greatest common divisor of two integers is the largest integer that divides them both.
 
The greatest common divisor of two integers is the largest integer that divides them both.
  

Revision as of 05:36, 7 March 2015

The greatest common divisor of two integers is the largest integer that divides them both.

There are many methods to calculate this. For example, the division-based Euclidean algorithm version may be programmed

function GreatestCommonDivisor( a, b:  Int64 ): Int64;
var
  temp : Int64;
begin
  while b <> 0 do
    begin
      temp := b ;
      b := a mod b ;
      a := temp ;
    end;
    result := a;
end;

See also