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 numpy as np
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)
    return divisors
d=make_divisors(x)
for i in range(len(d)):
  d.append(-d[i])
flag=False

for i in d:
  if flag==True:
    break
  tui=x//i
  ans=np.roots([5,10*i,10*i**2,5*i**3,i**4-tui])
  for j in ans:
    if flag==True:
      break
    if j.imag==0:
      a=i+round(j.real)
    if a**5-(round(j.real))**5==x:
      print(int(a),int(round(j.real)))
      flag=True
      break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
y = []
count1 = 0
flag = 0
for i in range(0, 130):
  y.append(i*i*i*i*i)
for i in y:
  if i == x:
    print("0 -" + str(count1))
    flag = 1
    break;
  count1 += 1
count1 = 0
for i in y:
  if flag == 1:
    break;
  count2 = 0
  for j in y[:count1]:
    y2 = i + j
    y3 = i - j
    if y2 == x:
      print(str(count1) + " -" + str(count2))
      flag = 1
      break;
    if y3 == x:
      print(str(count1) + " " + str(count2))
      flag = 1
      break;
    count2 +=1
  count1 += 1

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()
        if a**5 + b**5 == x:
            print(a, -b)
            exit()

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt
import fractions
import collections
import itertools
from collections import deque
X=int(input())
l=[]
for i in range(1,ceil(sqrt(X))+1):
    if X%i==0:
        l.append(i)
        l.append(X//i)
l=list(set(l))
l2=l
for i in range(len(l)):
    l2.append(-l[i])
#print(l2)
"""
for i in l:
    y=X//i
    print(i,y)
    if 60*y-35*pow(i,4)>=0:
        x=60*y-35*pow(i,4)
        print(sqrt(x))
        if sqrt(60*y-35*pow(i,4)).is_integer()==True:
            print(-10*pow(i,2)+sqrt(60*y-35*pow(i,4)))
            print(-10 * pow(i, 2) - sqrt(60 * y - 35 * pow(i, 4)))
            if (-10*pow(i,2)+sqrt(60*y-35*pow(i,4)))%15==0:
                ab=(-10*pow(i,2)+sqrt(60*y-35*pow(i,4)))//15
                if pow(i,2)-4*ab>=0:
                    if (-i+sqrt(pow(i,2)-4*ab)).is_integer()==True:
                        if (-i+sqrt(pow(i,2)-4*ab))%2==0:
                            b=(-i+sqrt(pow(i,2)-4*ab))//2
                            a=i-b
                            print(int(a),int(b))
                            break
                    elif (-i-sqrt(pow(i,2)-4*ab)).is_integer()==True:
                        if (-i-sqrt(pow(i,2)-4*ab))%2==0:
                            b=(-i-sqrt(pow(i,2)-4*ab))//2
                            a=i-b
                            print(int(a),int(b))
                            break
            elif (-10*pow(i,2)-sqrt(60*y-35*pow(i,4)))%15==0:
                ab=(-10*pow(i,2)-sqrt(60*y-35*pow(i,4)))//15
                if pow(i,2)-4*ab>=0:
                    if (-i+sqrt(pow(i,2)-4*ab)).is_integer()==True:
                        if (-i+sqrt(pow(i,2)-4*ab))%2==0:
                            b=(-i+sqrt(pow(i,2)-4*ab))//2
                            a=i-b
                            print(int(a),int(b))
                            break
                    elif (-i-sqrt(pow(i,2)-4*ab)).is_integer()==True:
                        if (-i-sqrt(pow(i,2)-4*ab))%2==0:
                            b=(-i-sqrt(pow(i,2)-4*ab))//2
                            a=i-b
                            print(int(a),int(b))
                            break
"""
l2.sort()
if len(l)!=0:
    for i in l2:
        x=X//i
        #print(i,x)
        n=(x-pow(i,4))/(pow(i,2)+1)
        #print(n)
        if (5*pow(i,4)+20*x)>=0:
            if sqrt((5*pow(i,4)+20*x)).is_integer()==True:
                #print(x,i)
                m=int(sqrt((5*pow(i,4)+20*x)))
                if (-5*i*i+m)%10==0:
                    y=(-5*i*i+m)//10
                    #print(i,y)
                    if pow(i,2)+4*y>=0:
                        if sqrt(pow(i,2)+4*y).is_integer()==True:
                            z=int(sqrt(pow(i,2)+4*y))
                            if (-i+z)%2==0:
                                b=(-i+z)//2
                                a=i+b
                                print(a,b)
                                break
                            elif (-i - z) % 2 == 0:
                                b = (-i - z) // 2
                                a = i + b
                                print(a, b)
                                break
                elif (-5*i*i-m)%10==0:
                    y=(-5*i*i+m)//10
                    #print(i,y)
                    if pow(i,2)+4*y>=0:
                        if sqrt(pow(i,2)+4*y).is_integer()==True:
                            z=int(sqrt(pow(i,2)+4*y))
                            if (-i+z)%2==0:
                                b=(-i+z)//2
                                a=i+b
                                print(a,b)
                                break
                            elif (-i - z) % 2 == 0:
                                b = (-i - z) // 2
                                a = i + b
                                print(a, b)
                                break

Submission status: Accepted

Solution code:
X = int(input())
Ahashtable = {}
Bhashtable = {}
i = 0

while True:
    x = i ** 5
    Ahashtable[x - X] = i
    Bhashtable[x + X] = i
    Bhashtable[-x + X] = -i
    if x in Ahashtable:
        print(Ahashtable[x], i)
        break
    if -x in Ahashtable:
        print(Ahashtable[-x], -i)
        break
    if x in Bhashtable:
        print(i, Bhashtable[x])
        break
    if -x in Bhashtable:
        print(i, Bhashtable[-x])
        break
    i += 1

Submission status: Accepted

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

import sys
import math

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def enumerate_factor(x):
    i = 1
    factors = []
    while i * i <= x:
        if x % i == 0:
            factors.append(i)
            if x // i != i:
                factors.append(x // i)
        i += 1
    return factors

def main():
    x = read(int)
    
    boundary = math.ceil(math.pow(x, 1/5))
    for factor in enumerate_factor(x):
        f = math.ceil(math.pow(factor, 1/5))
        for b in range(-boundary * 10, boundary * 10):
            a = b + factor
            if a**5 - b**5 == x:
                print(f"{a} {b}")
                return
            a = b - factor
            if a**5 - b**5 == x:
                print(f"{a} {b}")
                return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
x = int(input())
divisors = []
for i in range(1, int(x**0.5)+1):
    if x % i == 0:
        divisors.append(i)
        if i != x // i:
            divisors.append(x//i)
for j in divisors:
  for a in range(10000):
    b = a - j
    if a * a * a * a * a - b * b * b * b * b == x:
      print(a, b)
      sys.exit(0)