Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Fraction:
- @staticmethod
- def gcd(a, b):
- a = abs(a)
- b = abs(b)
- while b != 0:
- a, b = b, a % b
- return a
- def __init__(self, *args):
- if len(args) == 0:
- self.mi_num = 0
- self.mi_den = 1
- elif len(args) == 1:
- self.mi_num = args[0]
- self.mi_den = 1
- else:
- if args[1] < 0:
- self.mi_num = -1 * args[0]
- self.mi_den = -1 * args[1]
- else:
- self.mi_num = args[0]
- self.mi_den = args[1]
- checker = 0
- while checker != 1:
- checker = Fraction.gcd(self.mi_num, self.mi_den)
- self.mi_num = self.mi_num // checker
- self.mi_den = self.mi_den // checker
- if self.mi_num % self.mi_den == 0:
- self.mi_num = self.mi_num // self.mi_den
- self.mi_den = 0
- def __str__(self):
- if self.mi_den == 0:
- return str(self.mi_num)
- else:
- return str(self.mi_num) + "/" + str(self.mi_den)
- exec(open("input.txt").read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement