Project Nayuki

Calculate GCD (JavaScript)



This JavaScript program calculates the greatest common divisor (GCD) of the given two non-negative integers. The code implements big integer arithmetic, hence the numbers can be arbitrarily big (though computation time is the limiting factor). This implements the binary GCD algorithm, which runs in Θ(n2) time with respect to the bit length of the numbers. The source code is available for viewing.


More info