Problem:


Score : 400 points

Problem Statement

Give a pair of integers (A, B) such that A^5-B^5 = X.
It is guaranteed that there exists such a pair for the given integer X.

Constraints

1 \leq X \leq 10^9

X is an integer.

There exists a pair of integers (A, B) satisfying the condition in Problem Statement.

Input

Input is given from Standard Input in the following format:

X

Output

Print A and B, with space in between.
If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.

A B

Sample Input 1

33

Sample Output 1

2 -1

For A=2 and B=-1, A^5-B^5 = 33.

Sample Input 2

1

Sample Output 2

0 -1



Sample input:
33


Sample output:
2 -1

Submission status: Accepted

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

# from collections import deque

def linput(_t=int):
    return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

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

def main():
    X = int(input())
    # res = 0
    # for s in S.split("-"):
    #     res = max(res, len(s))

    # print(301**5 - 300**5)

    for A in reversed(range(-310,310)):
        for B in reversed(range(-310,310)):
            if A**5 - B**5 == X:
                print(A, B)
                return
    


    # print(res)

    # print(("No","Yes")[res%2])


main()

Submission status: Accepted

Solution code:
x = int(input().strip())
for i in range(-500,500):
    for j in range(-500,500):
        if pow(i,5)-pow(j,5)==x:
            print(i,j)
            exit()

Submission status: Accepted

Solution code:
X = int(input())
for i in range(-500,500):
    for j in range(-500,500):
        if (i**5) - (j**5) == X:
            print(i,j)
            exit()

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
X=int(input())
for A in range(-1000,1001):
    for B in range(-1000,1001):
        if A**5 - B**5 == X:
            print(A,B)
            exit()

Submission status: Accepted

Solution code:
x = int(input())
OP = [+1, -1]
for a in range(1000):
    for b in range(a + 1):
        for op1 in OP:
            for op2 in OP:
                if (op1 * a)**5 - (op2 * b)**5 == x:
                    print(op1 * a, op2 * b)
                    exit()

Submission status: Accepted

Solution code:
def f1(n):
    divs = []
    for i in range(1, int(n ** 0.5) + 1):  # range(n, int(n ** 0.5) - 1, -1)とすると非常に遅い！！
        if n % i == 0:
            divs.append(i)
            j = n // i
            if i != j:
                divs.append(j)
    return divs


X = int(input())
divs = f1(X)
INF = 10 ** 15

for p in divs:
    a = 0
    A = pow(a, 5)
    b = a - p
    B = pow(b, 5)
    while A - B < INF:
        if A - B == X:
            print(a, b)
            exit()
        a += 1
        A = pow(a, 5)
        b = a - p
        B = pow(b, 5)

Submission status: Accepted

Solution code:
X = int(input())
A = 0
B = 0
flag = 1
while flag:
  B = A * (-1)
  while B < A:
    #print(A, B)
    if A*A*A*A*A - B*B*B*B*B == X:
      print(A, B)
      flag = 0
      break
    B = B + 1
  A = A + 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
list_5 = []
a = 0
b = 0
for _ in range(-200,200):
    list_5.append(_**5)
for i in range(-200,200):
    if (n + list_5[i]) in list_5:
        b = i  
        a = list_5.index(n + list_5[i])
print(a-200, b-200)

Submission status: Accepted

Solution code:
X=int(input())
ans1=0
ans2=0
for a in range(-(10**3),10**3):
    for b in range(-(10**3),10**3):
        if a**5-b**5==X:
            ans1=a
            ans2=b
            break
print(ans1,ans2)

Submission status: Accepted

Solution code:
X = int(input())
for i in range(-5000, 5000):
    for j in range(-5000, 5000):
        if pow(i, 5)-pow(j, 5)==X:
            print(i, j)
            quit()

Submission status: Accepted

Solution code:
X = int(input())
 
for i in range(-200, 200):
  for j in range(-200, 200):
    if i **5 - j**5 ==X:
      print(str(i)+' ' +str(j))
      exit()

Submission status: Accepted

Solution code:
X = int(input())
for A in range(-1000, 1000):
    for B in range(-1000, 1000):
        if(A**5 - B**5 == X):
            print(A, B)
            exit(0)

Submission status: Accepted

Solution code:
import math

x = int(input())

fL = [i**5 for i in range(0, 1001)]

for i, f1 in enumerate(fL):
    for j, f2 in enumerate(fL):
        a = j
        b = i
        if f1 + f2 == x:
            print(a, -b)
            exit()
        if f1 - f2 == x:
            print(b, a)
            exit()

Submission status: Accepted

Solution code:
x=int(input())
for i in range(-120,121):
  for j in range(-120,121):
    if pow(i,5)-pow(j,5)==x:
      print(i,j);exit()

Submission status: Accepted

Solution code:
X = int(input())

for i in range(1000):
    for j in range(-1000, i):
        if i**5 - j**5 == X:
            print(i, j)
            exit()

Submission status: Accepted

Solution code:
import math

x = int(input())
a = []
b = []
for i in range(-1000,1000,1):
    a.append([i,i**5])
    b.append([i,i**5])

for ai,a5 in a:
    for bi,b5 in b:
        if a5 - b5 == x:
            print(ai,bi)
            exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from math import gcd

X = read_a_int()
# a5乗を全列挙？
candi = []
for i in range(10**10):
    if + (i + 1) ** 5 - i ** 5 > 10**11:
        break
    candi.append((i ** 5, i))
    candi.append((-i ** 5, -i))
candi.append((i ** 5, i))
candi.append((-i ** 5, -i))
# print(candi)

for a5, a in candi:
    for b5, b in candi:
        if a5 - b5 == X:
            print(a, b)
            exit()

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
x = ni()
ma = 200
for i in range(ma):
    for j in range(-ma,ma):
        if (i**5 - j**5) ==x:
            print(i,j)
            exit()

Submission status: Accepted

Solution code:
x = int(input())

for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            exit()

Submission status: Accepted

Solution code:
x=int(input())
d=[]
for i in range(1,int(x**(0.5))+1):
    if x%i==0:
        d.append(i)
        d.append(int(i/x))
for m in d:
    a=0
    f=0
    for b in range(-5*(10)**2,5*(10)**2,1):
        a=m+b
        if a**5-b**5==x:
            print(a,b)
            exit()

Submission status: Accepted

Solution code:
yes = False

x = int(input())
for i in range(-1000,1000+1):
    for j in range(-1000,1000+1):
        if i**5-j**5 == x:
            print(str(i)+" "+str(j))
            yes = True
            break
    if yes:
        break

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x = int(readline())

    ab = [i**5 for i in range(10**3)]

    C = combinations_with_replacement(ab, 2)
    for a, b in C:
        if a + b == x:
            print(int(pow(b, 0.2)), -int(pow(a, 0.2)))
            break
        
        if b - a == x:
            print(int(pow(b, 0.2)), int(pow(a, 0.2)))
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x = int(input())
c = []
d = []

for i in range(-1000,1000):
    a = int(i**5)
    c.append(a)
    d.append(i)

for j in range (len(c)):
    for k in range (len(c)):
        if c[j]-c[k] == x:
            s = str(d[j])
            t = str(d[k])
            break

print(s + ' ' + t)

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            a,b,c=(inp+[1])[:3]
            org_inp.append(inp)
        else:
            index=0
            a,b,c=(ls[i]+[1])[:3]
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

class Tree:
    def __init__(self,inp_size=None,init=True):
        if init:
            self.stdin(inp_size)
        return

    def stdin(self,inp_size=None):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1)
        return
    
    def listin(self,ls):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls)
        return

    def __str__(self):
        return  str(self.edges)

    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v

    def EulerTour(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append((-1,x))
        v=[None]*self.size
        v[x]=root_v
        et=[]
        while q:
            cb,ce=q.pop()
            et.append(ce)
            for nb,d in self.edges[ce]:
                if v[nb]==None:
                    q.append((nb,ce))
                    q.append((ce,nb))
                    v[nb]=func(v[ce],nb,d)
        vid=[[-1,-1]for i in range(self.size)]
        for i,j in enumerate(et):
            if vid[j][0]==-1:
                vid[j][0]=i
            else:
                vid[j][1]=i
        return v,et,vid
    
    def LCA_init(self,depth,et):
        self.st=SegTree(self.size*2-1,func=min,ide=inf)
        for i,j in enumerate(et):
            self.st.update(i,j)
        self.LCA_init_stat==True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            depth,et,vid=self.EulerTour(root)
            self.LCA_init(depth,et)
        return self.st.query(x,y+1)

## return prime factors of N as dictionary {prime p:power of p}
## within 2 sec for N = 2*10**20+7
def primeFactor(N):
    i,n=2,N
    ret={}
    d,sq=2,99
    while i<=sq:
        k=0
        while n%i==0:
            n,k,ret[i]=n//i,k+1,k+1
        if k>0 or i==97:
            sq=int(n**(1/2)+0.5)
        if i<4:
            i=i*2-1
        else:
            i,d=i+d,d^6
    if n>1:
        ret[n]=1
    return ret


## return the list of prime numbers in [2,N], using eratosthenes sieve
## within 2sec for N = 1.2*10**7
def PrimeNumSet(N):
    Max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList:
        if seachList[0] <= Max:
            break
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

## retrun LCM of numbers in list b
## within 2sec for no of B = 10*5  and  Bi < 10**6
def LCM(b,mo=10**9+7):
    prs=PrimeNumSet(max(b))
    M=dict(zip(prs,[0]*len(prs)))
    for i in b:
        dc=primeFactor(i)
        for j,k in dc.items():
            M[j]=max(M[j],k)
    
    r=1
    for j,k in M.items():
        if k!=0:
            r*=pow(j,k,mo)
            r%=mo
    return r

show_flg=False
show_flg=True

def func(y):
    global x
#    show('d',y)
    for i in range(int(x**0.2)-10**4,int(x**0.2)+10**5):
        if (i)**5-(i-y)**5==x:
            return i,i-y
    
    l,r=0,10**18+1
    while r-l>1:
        mid=(l+r)//2
        #show((l,r),(mid+y,mid),(mid+y)**5-mid**5)
        if (mid+y)**5-mid**5==x:
            return mid+y,mid
        if (mid+y)**5-mid**5>=x:
            r=mid
        else:
            l=mid
    
    l,r=-10**18,0
    while r-l>1:
        mid=(l+r)//2
        #show((l,r),(mid+y,mid),(mid+y)**5-mid**5)
        if (mid+y)**5-mid**5==x:
            return mid+y,mid
        if (mid+y)**5-mid**5>=x:
            l=mid
        else:
            r=mid
        
    return -1


x=I()

for i in range(int(x**0.2)-3,int(x**0.2)+3):
    if i**5==x:
        print(i,0)
        exit()

for i in range(1,int(x**0.5)+1+1):
    if x%i==0:
        
        k=func(i)
        if k==-1:
            0
        else:
            print(*k)
            exit()

        k=func(x//i)
        if k==-1:
            0#continue
        else:
            print(*k)
            exit()

Submission status: Accepted

Solution code:
X = int(input())
A = 1
while True:
    if X > A ** 5:
        S = X - A ** 5
        B = S ** (1 / 5) * (-1)
    else:
        S = A ** 5 - X
        B = S ** (1 / 5)
    if A ** 5 - int(B) ** 5 == X:
        break
    A += 1
print(A, int(B))

Submission status: Accepted

Solution code:
x = int(input())

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

Submission status: Accepted

Solution code:
def main():
    x = int(input())

    for a in range(-1000, 1001):
        for b in range(-1000, 1001):
            if a ** 5 - b ** 5 == x:
                print(a, b)
                exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x = int(input())


i = 0
a, b = 0, 0
while i**5 < x:
    i += 1
mx = i
for k in range(2 * (mx + 1)):
    for j in range(-k, k + 1):
        if k**5 - j**5 == x:
            a, b = k, j
print(a, b)

Submission status: Accepted

Solution code:
X=int(input())

div=[]
for i in range(1, int(X**0.5)+1):
        if X % i == 0:
            div.append(i)
            if i != X // i:
                div.append(X//i)

for k in div:
    x=X//k
    b=(-k)//2
    while True:
        f=((b+k)**5-b**5)//k
        if f==x:
            print(b+k,b)
            exit()
        if f>x:
            #print("over")
            break
        b-=1
    b=(-k)//2
    while True:
        f=((b+k)**5-b**5)//k
        if f==x:
            print(b+k,b)
            exit()
        if f>x:
            #print("over")
            break
        b+=1

Submission status: Accepted

Solution code:
x=int(input())
a=[]
for i in range(220):
  a.append(i**5)
for i in range(220):
  y=a[i]-x
  if y in a:
    print(i,a.index(y))
    break
  elif -y in a:
    print(i,-a.index(-y))
    break

Submission status: Accepted

Solution code:
import math
X = int(input())

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
    
divisors = make_divisors(X)
ans_A = 0
ans_B = 0
break_loop = False
for n in divisors:
    if X % 5 == n % 5:
        if X - n ** 5 != 0:
            B_cand = make_divisors(abs(X - n ** 5))
            for B in B_cand:
                A = B + n
                if A ** 5 - B ** 5 == X:
                    ans_A = A
                    ans_B = B
                    break_loop = True
                    break
                B = -B
                A = B + n
                if A ** 5 - B ** 5 == X:
                    ans_A = A
                    ans_B = B
                    break_loop = True
                    break
        else:
            ans_A = 0
            ans_B = -n
            break_loop = True
            break
    if break_loop:
        break

print(ans_A, ans_B)

Submission status: Accepted

Solution code:
# D

x = int(input())

a = int(x**(1/5))
b = int(abs(x-a**5)**(1/5))
i = 1
while True:
    if a**5 - b**5 != x and a**5 - (-b)**5 != x:
        if a**5 - x > (a+1)**5 - x:
            a += i
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
        else:
            a -= 1
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
    elif a**5 - b**5 == x:
        print(a,b)
        break

    else:
        print(a,-b)
        break

Submission status: Accepted

Solution code:
X = int(input())

flag = 0
for i in range(-200,200):
    for j in range(-200,200):
        if X == i**5 - j**5:
            print(i,j)
            flag = 1
            break
    if flag:
        break

Submission status: Accepted

Solution code:
x = int(input())
for a in range(10**3):
    for b in range(10**3):
        if (a**5 - b**5 == x):
            print(a, b)
            exit()
        elif (-a**5 - b**5 == x):
            print(-a, b)
            exit()
        elif (a**5 + b**5 == x):
            print(a, -b)
            exit()
        elif -a**5 + b**5 == x:
            print(-a, -b)
            exit()

Submission status: Accepted

Solution code:
def main():
  from itertools import combinations
  x = int(input())
  ls = [0]
  a = 0
  b = 0
  if x == 1:
    print(0, -1)
    exit()
  for i in range(1, 200):
    ls.append(i**5)
    ls.append(-i**5)
  ls.sort()
  for b in ls:
    if x + b in ls:
      a = x + b  
      break
  if a < 0:
    print(-1*int(pow(-a, 0.2)), end=' ')
  else:
    print(int(pow(a, 0.2)), end=' ')
  if b < 0:
    print(-1*int(pow(-b, 0.2)), end=' ')
  else:
    print(int(pow(b, 0.2)), end=' ')
  


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math

l = []
ans = []
x = int(input())

a = int( (x) ** (1/5) )

for i in range(a - 1000, a + 1000):
    l.append(i)

for i in range(1,len(l)):
    for j in range(len(l)):
        tmp = math.pow(l[j],5) - math.pow(l[i],5)
        if tmp == x:
            print(l[j],l[i])
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
x = int(input())

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

ans = None
d_ls = make_divisors(x)
for d in d_ls:
    for a in range(0, 1000):
        b = a-d
        c = a**5-b**5
        if c==x:
          ans = (a, b)
          break
    if ans is not None:
      break
print(ans[0], ans[1])

Submission status: Accepted

Solution code:
import collections
X = int(input())

for i in range(1000):
    for j in range(-1000,1000):
        if i**5 - j**5 == X:
            print(i,j)
            exit()

Submission status: Accepted

Solution code:
X=int(input())
import sys

for a in range(10**6):
    A=a**5
    if A-X>=0:
        l,r=max(a-119,0),a
        for b in range(10):
            m=(l+r)//2
            B=m**5
            if A-B-X>0:
                l=m
            elif A-B-X<0:
                r=m
            else:
                print(a,m)
                sys.exit()
    else:
        l,r=0,64
        for b in range(10):
            m=(l+r)//2
            B=m**5
            if A+B-X>0:
                r=m
            elif A+B-X<0:
                l=m
            else:
                print(a,-m)
                sys.exit()

Submission status: Accepted

Solution code:
def ff(n):
    if(n==0): return [0]
    if(n==1): return [1]
    ans=set([1,n])
    i=2
    while(i*i<=n):
        if(n%i==0):
            ans.add(n//i)
            ans.add(i)
        i+=1
    return ans

x=int(input())
fx=ff(abs(x))
A=-1000000
B=-1000000
for f in fx:
    if(A!=-1000000 and B!=1000000): break
    for i in range(-10000,10000):
        b,a=i,i+f
        z=a**5-b**5
        if(z==abs(x)):
            A=a
            B=b
            break
if(x<0): A,B=B,A
print(A,B)

Submission status: Accepted

Solution code:
X = int(input())
L = list()
i = 0
while True:
    if i ** 5 > 10 ** 11:
        break
    L.append(i ** 5)
    i += 1
flag = False
ret = ''
for i in range(len(L)):
    if flag:
        break
    for j in range(i+1, len(L)):
        if L[j] - L[i] == X :
            ret ='{} {}'.format(j,i)
            flag = True
            break
        if L[j] + L[i] == X :
            ret ='{} {}'.format(j,-i)
            flag = True
            break
print(ret)

Submission status: Accepted

Solution code:
import itertools

X = int(input())
nums = []
for i in range(121):
  nums.append(i**5)

comb = itertools.combinations(nums, 2)
ans = 0

for c in comb:
  a,b = c
  if c[0]+c[1] == X:
    print(int(a**(1/5)),int(-b**(1/5)))
  elif -c[0]+c[1] == X:
    print(int(-a**(1/5)),int(-b**(1/5)))
  elif c[0]-c[1] == X:
    print(int(a**(1/5)),int(b**(1/5)))
  elif -c[0]-c[1] == X:
    print(int(-a**(1/5)),int(b**(1/5)))

Submission status: Accepted

Solution code:
import math

X = int(input())

def decompose(n):
	result = []
	half = math.floor(math.sqrt(n))
	i = 2
	while i <= half:
		if n % i == 0:
			result.append(i)
			n //= i
			half = math.floor(math.sqrt(n))
		else:
			i += 1
	if n > 1:
		result.append(n)
	return result

facts = decompose(X)

fact_table = {}
for f in facts:
	if f not in fact_table:
		fact_table[f] = 1
	else:
		fact_table[f] += 1

facts = list(fact_table.items())
facts.sort()

def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

def find(num, n):
	if n >= len(facts):
		m = bisearch_smallest(lambda A: 5 * A ** 4 - 5 * (A - num) ** 4 >= 0, 0, 10 ** 9)
		i = bisearch_smallest(lambda A: A ** 5 - (A - num) ** 5 <= X, 0, m + 1)
		j = bisearch_smallest(lambda A: A ** 5 - (A - num) ** 5 >= X, m - 1, 10 ** 9)
		
		if i ** 5 - (i - num) ** 5 == X:
			return i, i - num
		if j ** 5 - (j - num) ** 5 == X:
			return j, j - num
	else:
		f, c = facts[n]
		for i in range(c + 1):
			ret = find(num, n + 1)
			if ret != None:
				return ret
			num *= f
	return None

A, B = find(1, 0)


print(A, B)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
import numpy as np

n=1000
X = int(input())

a = np.array(range(n))
ex = np.full(n, 5)

m = a*n+a.reshape(n,1)

b = np.power(a, ex)

plus = b + b.reshape(n,1)
minus = b - b.reshape(n,1)

plus = plus==X
minus = minus==X

if np.count_nonzero(plus):
  c = m[plus][0]
  ans = int(c/n), -int(c%n)
else:
  c = m[minus][0]
  ans = int(c/n), int(c%n)
  
print(ans[0], ans[1], sep=' ')

Submission status: Accepted

Solution code:
#!/usr/bin/env python

def main():
    x = int(input())
    for i in range(1000):
        for j in range(0, i+1):
            y = i ** 5 - j ** 5
            z = i ** 5 + j ** 5
            if x == y:
                a = i
                b = j
                break
            elif x == z:
                a = i
                b = -j
                break
    print(a, b)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# D - I hate Factorization

import numpy
# Z = int(input())

def abc166(X):
    B = 0


    while True:
        # minus
        B = -B
        A5 = X + B ** 5
        A = int(numpy.sign(A5) * numpy.power(numpy.abs(1.0 * A5), 1/5))

        if A5 == A ** 5:
            break

        # plus
        B = -B
        A5 = X + B ** 5
        A5 = X + B ** 5
        A = int(numpy.sign(A5) * numpy.power(numpy.abs(1.0 * A5), 1/5))

        if A5 == A ** 5:
            break

        B += 1

    # print('\t({0}) ^ 5 - ({1}) ^ 5 = {2}'.format(int(A), int(B), A ** 5 - B ** 5))
    print(A, B)

if __name__ == '__main__':
    # for x in range(10 ** 9 - 100, 10 ** 9):
    #     print('-----')
    #     print('x = {0}'.format(x))
    #     abc166(x)
    X = int(input())
    abc166(X)

Submission status: Accepted

Solution code:
x = int(input())
for a in range(1,1001):
    for b in range(-1001, 1001):
        if a**5 - b**5 == x:
            print("{} {}".format(a,b))
            exit()

Submission status: Accepted

Solution code:
X = int(input())
temp = []
N = 200
for i in range(-N, N):
    temp.append(i**5)

ok = []
flag = False

# print(temp)
for i in range(2 * N):
    if flag:
        break
    for j in range(2 * N):
        if flag:
            break
        if temp[i] + temp[j] == X:
            ok = [temp[i], temp[j]]
            flag = True

# print(ok)
ans = [0, 0]
mai = 1
if ok[0] == 0:
    ans[0] = 0
else:
    if ok[0] < 0:
        mai = -1
        ok[0] *= -1
    ans[0] = int(ok[0]**0.2)
    ans[0] = ans[0] * mai * -1

mai = 1
if ok[1] == 0:
    ans[1] = 0
else:
    if ok[1] < 0:
        mai = -1
        ok[1] *= -1
    ans[1] = int(ok[1]**0.2)
    ans[1] *= mai

print(str(ans[1]) + " " + str(ans[0]))

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
from sys import exit
from operator import mul
from functools import reduce


x = int(input())
X = x

if x == 1:
    print(0, -1)
    exit()

dic = dd(int)
for i in range(2, int(x**0.5) + 3):
    while x % i == 0:
        x //= i
        dic[i] += 1
if x != 1:
    dic[x] = 1

#print(dic)

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 serch(dif):
    target = X // dif
    for b in range(-1000, 1000):
        if 5 * b**4 + 10 * dif * b**3 + 10 * dif**2 * b**2 + 5 * dif**3 * b + dif**4 == target:
            print(-(b), -b-dif)
            exit()
    return None

pattern = [1]
for key in dic.keys():
    temp = []
    for num in range(dic[key] + 1):
        for i in pattern:
            temp.append(i * key**num)
    pattern = temp
#print(pattern)

for num in pattern:
    serch(num)



"""
b = -1
dif = 3
print(5 * b**4 + 10 * dif * b**3 + 10 * dif**2 * b**2 + 5 * dif**3 * b + dif**4)
"""