You are viewing a single comment's thread. Return to all comments →
from math import gcd
def simplify(nomerator, demirator): common_diviser = gcd(nomerator, demirator) return nomerator // common_diviser, demirator // common_diviser
def product_of_relations(relations): nomerator = 1 demirator = 1 for num, den in relations: nomerator *= num demirator *= den
return simplify(nomerator, demirator)
n = int(input()) relations = [tuple(map(int, input().split())) for _ in range(n)] result_nomerator, result_denominator = product_of_relations(relations) print(result_nomerator, result_denominator)
Seems like cookies are disabled on this browser, please enable them to open this website
Reduce Function
You are viewing a single comment's thread. Return to all comments →
from math import gcd
def simplify(nomerator, demirator): common_diviser = gcd(nomerator, demirator) return nomerator // common_diviser, demirator // common_diviser
def product_of_relations(relations): nomerator = 1 demirator = 1 for num, den in relations: nomerator *= num demirator *= den
n = int(input()) relations = [tuple(map(int, input().split())) for _ in range(n)] result_nomerator, result_denominator = product_of_relations(relations) print(result_nomerator, result_denominator)