Problem: AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time.  Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.

Submission attempts (in order):
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

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


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()
        x = t // ti
        x += 1 if t % ti else 0
        y = int(math.ceil(a / ai))
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()


import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

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


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        if ti == ai:
            t = max(t, a)
            a = max(t, a)

        x = t // ti
        x += 1 if t % ti else 0
        y = int(math.ceil(a / ai))
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()


import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

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


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        x = math.ceil(t / ti)
        y = math.ceil(a//ai)

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()


import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

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


def main():
    n = ni()
    t, a = ns()

    for _ in range(n - 1):
        ti, ai = ns()
        x = t // ti
        x += 1 if t % ti else 0
        y = int(math.ceil(a / ai))
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()


import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

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


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        # if ti == ai:
        #     t = max(t, a)
        #     a = max(t, a)
        #     continue

        x = t // ti
        x += 1 if t % ti else 0
        y = a//ai
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted