What is the fastest way to find the GCD of two numbers?

后端 未结 4 875
鱼传尺愫
鱼传尺愫 2020-12-22 12:48

I have an array of size n. I need to find the GCD of each element with a given number and if it\'s greater than 1, add it to another array. What\'s the fastest way to do thi

4条回答
  •  不思量自难忘°
    2020-12-22 13:23

    For small numbers use binary GCD (which is faster Euclid's GCD algorithm) & for large numbers try Lehmer's algorithm.

    Binary GCD: https://www.google.com/amp/s/www.geeksforgeeks.org/steins-algorithm-for-finding-gcd/amp/

提交回复
热议问题