# Innen szedtem:
# http://www.mathforum.com/epigone/math-learn/starcrumderm
""" Fraction osztály a törtekkel való számoláshoz.
   Van legkisebb közös többszörös és LNKO függvény.
"""

def lcm(a,b):
	"Largest Common Multiplier"
	return a*b/gcd(a,b)

def gcd(a,b):
	"Gratest Common Divisor"
	while b:
	   a,b = b, a%b
	return a


class Fraction:

         def __init__(self,numer,denom):
             self.numer = numer
             self.denom = denom
             self.simplify()

         def __mul__(self,other): 
              return Fraction(self.numer * other.numer,
                              self.denom * other.denom)

         def __add__(self,other):
	     thelcm = lcm(self.denom,other.denom)
	     a = thelcm/self.denom
	     b = thelcm/other.denom
	     return Fraction(self.numer*a 
                             + other.numer*b, thelcm)

         def __repr__(self):
             return "(%s/%s)" % (self.numer,self.denom)

         def simplify(self):
             thegcd = gcd(self.numer,self.denom) 
             self.numer = self.numer / thegcd
             self.denom = self.denom / thegcd

Tört = Fraction
print Tört
