Euclidean greatest common divisor for more than two numbers

前端 未结 6 1365
谎友^
谎友^ 2020-12-16 14:48

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

I believe programming language doesn\'t matter.

6条回答
  •  猫巷女王i
    2020-12-16 15:47

    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.

提交回复
热议问题