# William M. Farmer
# gcd.py
# 25 March 2012

# Implements Euclid's GCD algorithm

class GcdNonpositiveArguments(Exception):
  def __init__(self, value1, value2):
    self.value1 = value1
    self.value2 = value2
  def __str__(self):
    return str(self.value1) + ", " + str(self.value2)

def gcd(x,y):
  if x <= 0 or y <= 0:
    raise GcdNonpositiveArguments(x,y)
  else:
    while x != y:
      if x > y:
        x = x - y
      else:
        y = y - x
    return x