We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Reduce Function
Reduce Function
Sort by
recency
|
205 Discussions
|
Please Login in order to post a comment
from fractions import Fraction from functools import reduce def product(fracs): t = reduce (lambda x, y : x * y, fracs) return t.numerator, t.denominator if name == 'main': fracs = [] for _ in range(int(input())): fracs.append(Fraction(*map(int, input().split()))) result = product(fracs) print(*result)
def product(fracs):
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)