Euclidean greatest common divisor for more than two numbers

Bogdan Gusiev picture Bogdan Gusiev · Aug 5, 2009 · Viewed 16.1k times · Source

Can someone give an example for finding greatest common divisor algorithm for more than two numbers?

I believe programming language doesn't matter.

Answer

Sam Harwell picture Sam Harwell · Aug 5, 2009

Start with the first pair and get their GCD, then take the GCD of that result and the next number. The obvious optimization is you can stop if the running GCD ever reaches 1. I'm watching this one to see if there are any other optimizations. :)

Oh, and this can be easily parallelized since the operations are commutative/associative.