Ever heard of the Euclidean algorithm??
In mathematics, the Euclidean algorithm[a] (also called Euclid’s algorithm) is an efficient method for computing the greatest common divisor (GCD) of two integers, also known as the greatest common factor (GCF) or highest common factor (HCF).
I have just written a short python program for finding the GCD.. Enjoy..
# Efficient method for computing the greatest common divisor
# X and Y is the two numbers
print "Answer is " + str(a)