Problem p02690 (python)

Fixed submission:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

x = II()
def make_divisors(n):
	divisors = []
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n//i)

	# divisors.sort()
	return divisors

if x==0:
	print(0,0)
else:
	div = make_divisors(x)
	tmp = []
	for l in div:

		tmp.append(-1*l)
	div += tmp
	p = 0
	a = None
	b = None
	while(1):
		for l in div:
			s = p**5 - (p-l)**5
			# mp = -p
			# print(s)
			if s ==x:
				# print('!!!!!')
				a=p
				b=p-l
			if s==(-x):
				# print(p,l)
				b=p
				a=p-l

			# s = mp**5-(mp-l)**5
			# if s ==x:
			# 	a=mp
			# 	b=mp-l
			# elif s==(-x):
			# 	b=mp-l
			# 	a=mp

		if a is not None:
			break
		p += 1
	print(a,b)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

x = II()
import sympy
div = sympy.divisors(x)
tmp = []
for l in div:
	print(l)
	tmp.append(-1*l)
div += tmp
p = 0
a = None
b = None
while(1):
	for l in div:
		s = p**5 - (p-l)**5
		# print(s)
		if s ==x:
			a=p
			b=p-l
		elif s==(-x):
			a=l-p
			b=-p
	if a is not None:
		break
	p += 1
print(a,b)