Buggy python submission (verdict: Time Limit Exceeded):

import math


def fact(x):
    for cand in range(2, math.ceil(math.sqrt(x)) + 1):
        q, r = divmod(x, cand)
        if r == 0:
            return min(q, cand), max(q, cand)
    return 1, x


# def check(a, b):
#     a2 = a * a
#     a3 = a2 * a
#     a4 = a3 * a
#     b2 = b * b
#     b3 = b2 * b
#     b4 = b3 * b
#     return a4 + a3*b + a2*b2 + a*b3 + b4

def pow5(x):
    return x ** 5


def func(a, b):
    return pow5(a) - pow5(b)


def submit():
    x = int(input())

    if x == 1:
        print("0 -1")
        return

    q1, q2 = fact(x)
    # パターン1, a, b > 0
    a = 0
    b = -q1
    f = func(a, b)
    while f != x:
        a += 1
        b += 1
        f = func(a, b)
    print("{} {}".format(a, b))


        
submit()

Fixed submission:


def submit():
    x = int(input())

    for a in range(-200, 200):
        for b in range(-200, 200):
            if a ** 5 - b ** 5 == x:
                print(a, b)
                return


if __name__ == "__main__":
    submit()

Buggy python submission (verdict: Time Limit Exceeded):

import math


def fact(x):
    for cand in range(2, math.ceil(math.sqrt(x)) + 1):
        q, r = divmod(x, cand)
        if r == 0:
            return min(q, cand), max(q, cand)
    return 1, x


# def check(a, b):
#     a2 = a * a
#     a3 = a2 * a
#     a4 = a3 * a
#     b2 = b * b
#     b3 = b2 * b
#     b4 = b3 * b
#     return a4 + a3*b + a2*b2 + a*b3 + b4

def pow5(x):
    return x ** 5


def func(a, b):
    return pow5(a) - pow5(b)


def submit():
    x = int(input())

    if x == 1:
        print("0 -1")
        return

    q1, q2 = fact(x)
    # パターン2 a > 0, b < 0
    a = q1
    b = 0
    f = func(a, b)
    while a > 0 and f != x:
        a -= 1
        b -= 1
        f = func(a, b)
    if f == x:
        print("{} {}".format(a, b))
        return

    # パターン1, a, b > 0
    a = q1
    b = 0
    f = func(a, b)
    while f < x:
        a += 1
        b += 1
        f = func(a, b)
    if f == x:
        print("{} {}".format(a, b))
        return

    # パターン3 a, b < 0
    a = 0
    b = -q1
    f = func(a, b)
    while f != x:
        a -= 1
        b -= 1
        f = func(a, b)
    if f == x:
        print("{} {}".format(a, b))
        return

        
submit()

Fixed submission:


def submit():
    x = int(input())

    for a in range(-200, 200):
        for b in range(-200, 200):
            if a ** 5 - b ** 5 == x:
                print(a, b)
                return


if __name__ == "__main__":
    submit()

Buggy python submission (verdict: Time Limit Exceeded):

import math


def fact(x):
    for cand in range(2, math.ceil(math.sqrt(x)) + 1):
        q, r = divmod(x, cand)
        if r == 0:
            return min(q, cand), max(q, cand)
    return 1, x


# def check(a, b):
#     a2 = a * a
#     a3 = a2 * a
#     a4 = a3 * a
#     b2 = b * b
#     b3 = b2 * b
#     b4 = b3 * b
#     return a4 + a3*b + a2*b2 + a*b3 + b4

def pow5(x):
    return x ** 5


def func(a, b):
    return pow5(a) - pow5(b)


def submit():
    x = int(input())

    if x == 1:
        print("0 -1")
        return

    q1, q2 = fact(x)

    # パターン1, a, b > 0
    a = q1
    b = 0
    f = func(a, b)
    while f < x:
        a += 1
        b += 1
        f = func(a, b)
    if f == x:
        print("{} {}".format(a, b))
        return

    # パターン2 a > 0, b < 0
    a = q1 - 1
    b = -1
    f = func(a, b)
    while a > 0 and f != x:
        a -= 1
        b -= 1
        f = func(a, b)
    if f == x:
        print("{} {}".format(a, b))
        return

    # パターン3 a, b < 0
    a = 0
    b = -q1
    f = func(a, b)
    while f != x:
        a -= 1
        b -= 1
        f = func(a, b)
    if f == x:
        print("{} {}".format(a, b))
        return

        
submit()

Fixed submission:


def submit():
    x = int(input())

    for a in range(-200, 200):
        for b in range(-200, 200):
            if a ** 5 - b ** 5 == x:
                print(a, b)
                return


if __name__ == "__main__":
    submit()