Problem:


みんなでジョギング

 赤ベコ小学校では、生徒全員が参加する、ちょっと変わったジョギングをします。生徒は、それぞれ独自の周回コースを、自分のペースで走ります。それぞれ自分のコースを 1 周すると小学校に戻ってきます。全員が小学校を同時にスタートしてから、全員が同時に小学校で最初に出会うのは、それぞれ何周したときでしょうか?

 生徒の人数 n、各生徒のコースの 1 周の距離 d (km)  、各生徒の走る速さ v (km/時間)を入力とし、全員が小学校を同時にスタートしてから次に同時に小学校に位置するのは、各生徒がそれぞれ何周したときかを出力するプログラムを作成してください。なお、各生徒は 231-1 周を超えて走ることはありません。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。

n
d1 v1
d2 v2
:
dn vn

1 行目に生徒の人数 n (2 ≤ n ≤ 10) が与えられます。続く n 行に i 人目の生徒のコースの１周の距離 di (1 ≤ di ≤ 10000) と走る速さ vi (1 ≤ vi ≤ 10000) が与えられます。

データセットの数は 2000 を超えません。

Output

入力データセットごとに、各生徒の周回数を出力します。各生徒の周回数は入力の順番に従ってそれぞれ１行に出力してください。

Sample Input

2
4 3
5 4
5
789 289
166 46
9 4
617 252
972 303
2
8 5
32 20
0

Output for the Sample Input

15
16
1598397732
1209243492
1939462992
1782294192
1360317793
1
1



Sample input:
2
4 3
5 4
5
789 289
166 46
9 4
617 252
972 303
2
8 5
32 20
0


Sample output:
15
16
1598397732
1209243492
1939462992
1782294192
1360317793
1
1

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
from sys import stdin

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

while(True):
    n = int(stdin.readline())
    if not n: break
    s = [list(map(int,stdin.readline().split())) for _ in range(n)]
    lcmde = lcm_list([r[1] for r in s])
    lcmnu = lcm_list([int(r[0]*lcmde/r[1]) for r in s])
    print("\n".join( str(int(lcmnu/lcmde*r[1]/r[0])) for r in s))

Submission status: Wrong Answer

Solution code:
import copy

def main():
    _data = copy.deepcopy(data)
    while 1 < len(_data):
        d1, v1 = _data[0]
        d2, v2 = _data[1]
        l = f1(v1, v2)
        v = l
        m1, m2 = list(f2(l, v1, v2))
        d = f1(d1*m1, d2*m2)
        for i in range(2): del _data[0]
        _data.append([d, v])
    else:
        f3(_data[0])

def f1(a, b):
    x, y = (a, b) if a >= b else (a, b)
    g = gcd(x, y)
    return lcm(x, y, g)
    
def f2(l, *s):
    for v in s:
        yield l/v
        
def f3(_data):
    x, y = _data
    for d, v in data:
        print int((float(x)/y)/(float(d)/v))
        
def gcd(x, y):
    while y != 0:
        x = x-(x/y)*y
        x, y = y, x
    else:
        return x
    
def lcm(x, y, g):
    return (x*y)/g

while True:
    n = int(raw_input())
    if n == 0: break
    data = [map(int, raw_input().split()) for i in range(n)]
    main()

Submission status: Wrong Answer

Solution code:
import copy

def main():
    _data = copy.deepcopy(data)
    while 1 < len(_data):
        d1, v1 = _data[0]
        d2, v2 = _data[1]
        l = f1(v1, v2)
        v = l
        m1, m2 = list(f2(l, v1, v2))
        d = f1(d1*m1, d2*m2)
        for i in range(2): del _data[0]
        _data.append([d, v])
    else:
        f3(_data[0])

def f1(a, b):
    x, y = (a, b) if a >= b else (b, a)
    g = gcd(x, y)
    return lcm(x, y, g)
    
def f2(l, *s):
    for v in s:
        yield l/v
        
def f3(_data):
    x, y = _data
    for d, v in data:
        print int((float(x)/y)/(float(d)/v))
        
def gcd(x, y):
    while y != 0:
        x = x-(x/y)*y
        x, y = y, x
    else:
        return x
    
def lcm(x, y, g):
    return (x*y)/g

while True:
    n = int(raw_input())
    if n == 0: break
    data = [map(int, raw_input().split()) for i in range(n)]
    main()

Submission status: Wrong Answer

Solution code:
""" Created by Jieyi on 10/4/16. """
import io
import sys
from fractions import gcd

if len(sys.argv) > 1:
    filename = sys.argv[1]
    inp = ''.join(open(filename, "r").readlines())
    sys.stdin = io.StringIO(inp)


def lcm(x, y):
    return (x * y) / gcd(x, y)


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = []
        for _ in range(n):
            students.append(list(map(int, input().split())))
        answer_list = algorithm(students)
        for ans in answer_list:
            print(ans)


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
from sys import stdin

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

while(True):
    n = int(stdin.readline())
    if not n: break
    s = [list(map(int,stdin.readline().split())) for _ in range(n)]
    lcmde = lcm_list([r[1] for r in s])
    lcmnu = lcm_list([r[0]*lcmde//r[1] for r in s])
    print("\n".join( str(lcmnu*r[1]//lcmde//r[0]) for r in s))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
from sys import stdin

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

while(True):
    n = int(stdin.readline())
    if not n: break
    s = [list(map(int,stdin.readline().split())) for _ in range(n)]
    lcmde = lcm_list([r[1] for r in s])
    lcmnu = lcm_list([r[0]*lcmde//r[1] for r in s])
    print("\n".join( str(lcmnu*r[1]//lcmde//r[0]) for r in s))

Submission status: Accepted

Solution code:
def gcm(a,b):
    if a==0 or b==0:
        return a
    else:
        [a,b]=[max(a,b),min(a,b)]
        return gcm(b,a%b)

def lcf(a,b,g):
    return a*b/g
    
while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        cdata=[]
        ratio=[]
        for i in range(n):
            cdata.append([int(x) for x in raw_input().split()])
        for i in range(n-1):
            a=cdata[0][0]*cdata[i+1][1]
            b=cdata[i+1][0]*cdata[0][1]
            g=gcm(a,b)
            ratio.append([b/g,a/g])
        ll=ratio[0][0]
        for r in range(n-2):
            g=gcm(ll,ratio[r+1][0])
            ll=lcf(ll,ratio[r+1][0],g)
        print ll
        for r in ratio:
            print r[1]*ll/r[0]

Submission status: Accepted

Solution code:
from sys import stdin
readline = stdin.readline


from fractions import Fraction
from fractions import gcd
from functools import reduce

from collections import namedtuple
Runner = namedtuple('Runner', 'd v')

def common_denominator(r0, ri):
    return Fraction(r0.d * ri.v, r0.v * ri.d).denominator

def lcm(a, b):
    return a * b / gcd(a, b)

while True:
    n = int(readline())
    if n == 0:
        break
    runners = [Runner(*map(int, readline().split())) for _ in range(n)]
    
    denominators = [common_denominator(runners[0], ri) for ri in runners[1:]]
    
    round_of_0 = int(reduce(lcm, denominators))
    time = Fraction(runners[0].d * round_of_0, runners[0].v)
    
    for ri in runners:
        print(time * ri.v / ri.d)

Submission status: Accepted

Solution code:
import copy

def main():
    _data = copy.deepcopy(data)
    while 1 < len(_data):
        d1, v1 = _data[0]
        d2, v2 = _data[1]
        l = f1(v1, v2)
        v = l
        m1, m2 = list(f2(l, v1, v2))
        d = f1(d1*m1, d2*m2)
        for i in range(2): del _data[0]
        _data.append([d, v])
    else:
        f3(_data[0])

def f1(a, b):
    x, y = (a, b) if a >= b else (b, a)
    g = gcd(x, y)
    return lcm(x, y, g)
    
def f2(l, *s):
    for v in s:
        yield l/v
        
def f3(_data):
    d1, v1 = _data
    for d2, v2 in data:
        ans = str((float(d1)/v1)/(float(d2)/v2))
        print int(ans[:-2])
        
def gcd(x, y):
    while y != 0:
        x = x-(x/y)*y
        x, y = y, x
    else:
        return x
    
def lcm(x, y, g):
    return (x*y)/g

while True:
    n = int(raw_input())
    if n == 0: break
    data = [map(int, raw_input().split()) for i in range(n)]
    main()

Submission status: Accepted

Solution code:
# AOJ 0211: Jogging
# Python3 2018.6.25 bal4u

def lcm(a, b):
	return a // gcd(a, b) * b

def gcd(a, b):
	while b != 0:
		r = a % b
		a, b = b, r
	return a

def ngcd(n, a):  # aが整数のリスト
	if n == 1: return a[0]
	g = gcd(a[0], a[1]);
	for i in range(2, n):
		if g == 1: break
		g = gcd(g, a[i])
	return g;

def nlcm(n, a):  # aが整数のリスト
	if n == 1: return a[0];
	g = gcd(a[0], a[1]);
	c = a[0] //g *a[1]
	for i in range(2, n):
		g = gcd(c, a[i])
		c = c //g * a[i]
	return c

while True:
	n = int(input())
	if n == 0: break
	d, v = [], []
	for i in range(n):
		a, b = map(int, input().split())
		g = gcd(a, b)
		a //= g
		b //= g
		d.append(a)
		v.append(b)
	g = nlcm(n, d);
	for i in range(n): d[i] = (g//d[i])*v[i]
	g = ngcd(n, d)
	for i in range(n): print(d[i]//g)

Submission status: Accepted

Solution code:
import fractions
def lcm(a,b):
    return a*b/fractions.gcd(a,b)

while True:
    n=input()
    if n==0:break
    D,T=[],[]
    for i in range(n):
        d,t=map(int,raw_input().split())
        D.append(d)
        T.append(t)
    dn=reduce(lcm,D)
    nm=[T[i]*dn/D[i] for i in range(n)]
    g=reduce(fractions.gcd,nm)
    for i in range(n):
        print nm[i]/g

Submission status: Accepted

Solution code:
def gcd(a,b):
	return a if b==0 else gcd(b,a%b)

while 1:
	n=input()
	if n==0:break
	s=[map(int,raw_input().split()) for i in range(n)]
	c=1
	for i in s:
		c=c*i[1]/gcd(c,i[1])
	for i in range(n):
		s[i]=c*s[i][0]/s[i][1]
	c=1
	for i in s:
		c=c*i/gcd(c,i)
	for i in s:
		print c/i

Submission status: Accepted

Solution code:
def gcd(a,b):
	return a if b==0 else gcd(b,a%b)

while 1:
	n=input()
	if n==0:break
	s=[map(int,raw_input().split()) for i in range(n)]
	t=c=1
	for i in s:t=t*i[1]/gcd(t,i[1])
	for i in range(n):
		s[i]=t*s[i][0]/s[i][1]
		c=c*s[i]/gcd(c,s[i])
	for i in s:print c/i

Submission status: Accepted

Solution code:
def g(a,b):
	return a if b==0 else g(b,a%b)

while 1:
	n=input()
	if n==0:break
	s=[map(int,raw_input().split()) for i in [1]*n]
	t=c=1
	for i in s:t*=i[1]/g(t,i[1])
	for i in range(n):
		s[i]=t*s[i][0]/s[i][1]
		c*=s[i]/g(c,s[i])
	for i in s:print c/i

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def lcm(a, b):
    return (a // gcd(a, b)) * b

while True:
    n = int(input())
    if n == 0:
        break

    students = [0] * n
    v_lcm = 1
    for i in range(n):
        students[i] = list(map(int, input().split()))
        v_lcm = lcm(v_lcm, students[i][1])
    mul_lcm = 1
    for i in range(n):
        mul_lcm = lcm(mul_lcm, (v_lcm // students[i][1]) * students[i][0])
    for i in range(n):
        print(mul_lcm // (v_lcm // students[i][1]) // students[i][0])

Submission status: Accepted

Solution code:
def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def _LCM(a,b):
    return a*b//GCD(a,b)

def LCM(array):
    lcm=1
    for i in array:
        lcm=_LCM(lcm,i)
    return lcm

while True:
    n=int(input())
    if n==0:
        break

    d=[]
    v=[]
    for i in range(n):
        _d,_v=[int(j) for j in input().split(" ")]
        d.append(_d)
        v.append(_v)

    V=1
    for i in range(n):
        V=V*v[i]
    array=[d[i]*V//v[i] for i in range(n)]
    lcm=LCM(array)
    for i in range(n):
        print(lcm*v[i]//(V*d[i]))

Submission status: Accepted

Solution code:
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def lcm(m, n):
    return m//gcd(m, n)*n
while 1:
    N = int(input())
    if N == 0:
        break
    X = []
    D = []; V = []
    for i in range(N):
        d, v = map(int, input().split())
        g = gcd(d, v)
        d //= g; v //= g
        D.append(d); V.append(v)
    vg = V[0]
    for v in V:
        vg = gcd(vg, v)
    dl = 1
    for d in D:
        dl = lcm(dl, d)
    for d, v in zip(D, V):
        print(v//vg*dl//d)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Jogging
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0211

"""
import sys
from math import gcd
from functools import reduce

def solve(n, data):
    res = []
    for i in range(n):
        t = 1
        for j in range(n):
            t *= (data[j][0], data[j][1])[i==j]
        res.append(t)
    g = reduce(gcd, res)
    return [r//g for r in res]


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [[int(i) for i in input().split()] for _ in range(n)]
        ans = solve(n, data)
        print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

def gcd_mul(numbers):
    return reduce(gcd, numbers)

def lcm(x, y):
    return x * y // gcd(x, y)

def lcm_mul(numbers):
    return reduce(lcm, numbers)

def solve():
    from sys import stdin
    file_input = stdin
    
    from operator import mul
    
    while True:
        n = int(file_input.readline())
        if n == 0:
            break
        d_list = []
        v_list = []
        for i in range(n):
            d, v = map(int, file_input.readline().split())
            d_list.append(d)
            v_list.append(v)
        
        mv = reduce(mul, v_list)
        x = [mv * d // v for d, v in zip(d_list, v_list)]
        l = lcm_mul(x)
        
        for s in x:
            print(l // s)

solve()

Submission status: Runtime Error

Solution code:
import copy

def main():
    _data = copy.deepcopy(data)
    while 1 < len(_data):
        d1, v1 = _data[0]
        d2, v2 = _data[1]
        l = f1(v1, v2)
        v = l
        m1, m2 = list(f2(l, v1, v2))
        d = f1(d1*m1, d2*m2)
        for i in range(2): del _data[0]
        _data.append([d, v])
    else:
        f3(_data[0])

def f1(a, b):
    x, y = (a, b) if a >= b else (b, a)
    g = gcd(x, y)
    return lcm(x, y, g)
    
def f2(l, *s):
    for v in s:
        yield l/v
        
def f3(_data):
    d1, v1 = _data
    for d2, v2 in data:
        ans = str((float(d1)/v1)/(float(d2)/v2))
        print int(ans[:-2])
        
def gcd(x, y):
    while y != 0:
        x = x-(x/y)*y
        x, y = y, x
    else:
        return x
    
def lcm(x, y, g):
    return (x*y)/g

while True:
    n = int(raw_input())
    if n == 0: break
    data = [map(int, line.rstrip().split()) for line in open('s.txt')]
    main()

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    while y:
        x, y = y, x % y

    return x


def lcm(x, y):
    l_lcm = (x * y) // gcd(x, y)
    return l_lcm


def mul_lcm(array):
    l = lcm(array[0], array[1])
    if len(array) > 3:
        for i in range(2, len(array)):
            l = lcm(array[i], l)
    return l


def algorithm(students):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])

    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = []
        for _ in range(n):
            students.append(list(map(int, input().split())))
        answer_list = algorithm(students)
        for ans in answer_list:
            print(ans)


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 10/4/16. """
import io
import sys

if len(sys.argv) > 1:
    filename = sys.argv[1]
    inp = ''.join(open(filename, "r").readlines())
    sys.stdin = io.StringIO(inp)


def gcd(x, y):
    while y:
        x, y = y, x % y

    return x


def lcm(x, y):
    l_lcm = (x * y) // gcd(x, y)
    return l_lcm


def mul_lcm(array):
    l = lcm(array[0], array[1])
    if len(array) > 3:
        for i in range(2, len(array)):
            l = lcm(array[i], l)
    return l


def algorithm(students):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = []
        for _ in range(n):
            students.append(list(map(int, input().split())))
        answer_list = algorithm(students)
        for ans in answer_list:
            print(ans)


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def lcm(x, y):
    return (x * y) / gcd(x, y)


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = []
        for _ in range(n):
            students.append(list(map(int, input().split())))
        answer_list = algorithm(students)
        for ans in answer_list:
            print(ans)


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 10/4/16. """
import io
import sys
from fractions import gcd

if len(sys.argv) > 1:
    filename = sys.argv[1]
    inp = ''.join(open(filename, "r").readlines())
    sys.stdin = io.StringIO(inp)


def lcm(x, y):
    return (x * y) / gcd(x, y)


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = [[-1, -1] for _ in range(10)]
        for i in range(n):
            students[i][0], students[i][1] = list(map(int, input().split()))
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 10/4/16. """
import io
import sys
from fractions import gcd

if len(sys.argv) > 1:
    filename = sys.argv[1]
    inp = ''.join(open(filename, "r").readlines())
    sys.stdin = io.StringIO(inp)


def lcm(x, y):
    return (x * y) / gcd(x, y)


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = [[-1, -1] for _ in range(20)]
        for i in range(n):
            students[i][0], students[i][1] = list(map(int, input().split()))
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from fractions import gcd

def lcm(x, y):
    return (x * y) / gcd(x, y)


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = [[-1, -1] for _ in range(20)]
        for i in range(n):
            students[i][0], students[i][1] = list(map(int, input().split()))
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

if len(sys.argv) > 1:
    filename = sys.argv[1]
    inp = ''.join(open(filename, "r").readlines())
    sys.stdin = io.StringIO(inp)


def lcm(x, y):
    return int((x * y) / math.gcd(x, y))


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = [[-1, -1] for _ in range(20)]
        for i in range(n):
            students[i][0], students[i][1] = list(map(int, input().split()))
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

def lcm(x, y):
    return int((x * y) / math.gcd(x, y))


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    denominator_lcm = mul_lcm([y for _, y in students])
    for i in range(len(students)):
        students[i][0] *= int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm([x for x, _ in students])

    return [int(molecular_lcm / students[i][0]) for i in range(len(students))]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = [[-1, -1] for _ in range(20)]
        for i in range(n):
            students[i][0], students[i][1] = list(map(int, input().split()))
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

def lcm(x, y):
    return int((x * y) / math.gcd(x, y))


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    den = [students[i][1] for i in range(n)]
    denominator_lcm = mul_lcm(den)

    ans = [-1] * 20
    for i in range(n):
        ans[i] = students[i][0] * int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm(ans[0:n])

    return [int(molecular_lcm / ans[i]) for i in range(n)]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        students = [[-1, -1] for _ in range(20)]
        for i in range(n):
            students[i][0], students[i][1] = list(map(int, input().split()))
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 10/4/16. """
import io
import sys
import math

if len(sys.argv) > 1:
    filename = sys.argv[1]
    inp = ''.join(open(filename, "r").readlines())
    sys.stdin = io.StringIO(inp)


def lcm(x, y):
    return int((x * y) / math.gcd(x, y))


def mul_lcm(array):
    l = array[0]
    if len(array) > 1:
        for i in range(1, len(array)):
            l = lcm(array[i], l)

    return l


def algorithm(students, n):
    den = [students[i][1] for i in range(n)]
    denominator_lcm = mul_lcm(den)

    ans = [-1] * 20
    for i in range(n):
        ans[i] = students[i][0] * int(denominator_lcm / students[i][1])
    molecular_lcm = mul_lcm(ans[0:n])

    return [int(molecular_lcm / ans[i]) for i in range(n)]


def input_sample():
    while True:
        n = int(input())
        if n == 0:
            break

        # students = [[-1, -1] for _ in range(20)]
        # for i in range(n):
        #     students[i][0], students[i][1] = list(map(int, input().split()))
        students = [list(map(int, input().split(' '))) for _ in range(n)]
        answer_list = algorithm(students, n)

        for i in range(n):
            print(answer_list[i])


def main():
    input_sample()


if __name__ == '__main__':
    main()