Problem p02690 (python)

Fixed submission:
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def check(a,b,x):
    a=round(a)
    return a**5 - b**5 == x

def fifthroot(n):
    for i in range(int(n**(1/5)+1)) :
        if i**5==n:
            return i
    return -1

def main():
    x = int(input().strip())
    # b>=0 のとき
        # #
        # a=(x + b**5)**(1/5)
        # eprint('a ',end=':\n')
        # eprint(a)
        # if check(a,b,x):
        #     eprint("b>=0")
        #     print(int(a),b)
        #     return            

        #
        # if a.is_integer():
        #     eprint("b>=0")
        #     print(a,b)
        #     return
    
    # b<0の場合
    for a in range(1,10**9):
        if x - a**5 < 0:
            break
        # b=(x - a**5) ** (1/5)
        b=fifthroot(x - a**5)
        if b!=-1:
            eprint("b<0")
            print(a,-int(b))
            return

    for b in range(1,10**9):
        if fifthroot(x + b**5)!=-1:
            eprint("b>=0")
            a=fifthroot(x + b**5)
            print(a,b)
            return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def fifthroot(n):
    for i in range(-int(n**(1/5)+1),int(n**(1/5)+1)) :
        if i**5==n:
            return i
    return -1

def main():
    x = int(input().strip())
    for a in range(-10*3, 10**3):
        b_candidate = fifthroot(x - a**5)
        if b_candidate!=-1:
            b=b_candidate
            print(a,b)
            return


if __name__ == '__main__':
    main()