use euclidean subtraction algorithm to calculate greatest common divisor