Ram is the mathematical genius of GCECT. His girlfriend, doesn't like this obsession for Maths. Ram was too tired off such non-mathemetical relationship. As a result they were going away from each other day by day and their relationship was on the verge of BREAKUP. But her heart said something else.She still used to love Romok and was ready to do anything to keep their relationship intact. Having heard this, Romok asked her to solve a problem, just to prove herself eligible of being the girlfriend of Ram. So he gave her N fractions and asked her to find the product of all those fractions in the simplified form.

Input
1
3
1 2
2 1
5 2


Output
5 2


Solution

def hcf(a,b):
c=10
while(c):
c= a%b
a= b
b= c
return a;
t= int(input())
i=0
while i<t:
n=int(input())
j=0
nu=1
de=1
while j<n :
x,y=map(int, raw_input().split())
nu*= x
de*= y
j=j+1
hc=hcf(nu, de)
print nu/hc, de/hc
i=i+1






if you have any problem in this code, take a screenshot and contact with Rishabh Chaubey.
Previous Post Next Post