Euclidean algorithm for GCD

This topic has expert replies
Senior | Next Rank: 100 Posts
Posts: 58
Joined: Sun Jun 17, 2007 8:24 am

Euclidean algorithm for GCD

by vish150783 » Sat Dec 06, 2008 11:20 am
For those problems which require calculation of GCD..one may use this eucliedean algorithm which is more efficient than prime factorization.

A much more efficient method is the Euclidean algorithm, which uses the division algorithm in combination with the observation that the gcd of two numbers also divides their difference: divide 84 by 18 to get a quotient of 4 and a remainder of 12. Then divide 18 by 12 to get a quotient of 1 and a remainder of 6. Then divide 12 by 6 to get a remainder of 0, which means that 6 is the gcd.

I tried timing to see if its true.

problem GCD for 92 and 20.
Prime factorization - 40s.
Euclidean - 18s

not only does prime factorization take long it may confuse sometimes during overlap..

Hope this helps cheers..

User avatar
Legendary Member
Posts: 871
Joined: Wed Aug 13, 2008 7:48 am
Thanked: 48 times

by stop@800 » Sat Dec 06, 2008 11:32 am
Great tip.

We all know about it but never use it.