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

Solution in Scala (2.13.1) (judge verdict: Wrong Answer)

import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val x = in.readLine().toInt

    def primes(x: Int): List[Int] = {
      @tailrec
      def inner(ps: List[Int], x: Int, n: Int): List[Int] = {
        if (x == 1) {
          ps
        } else if (x % n == 0) {
          inner(n :: ps, x / n, 2)
        } else {
          inner(ps, x, n + 1)
        }
      }

      if (x == 1) {
        1 :: Nil
      } else {
        inner(Nil, x, 2)
      }
    }

    val ps = primes(x).sorted

    val ambs = ps.scanLeft(1) {
      case (acc, p) => acc * p
    }.tail

    def findAB(amb: Int): Option[(Int, Int)] = {
      val target = x / amb

      @tailrec
      def inner(a: Int, b: Int): Option[(Int, Int)] = {
        val f = a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b + b * b * b * b
        if (f == target) {
          Some(a, b)
        } else if (b < 0 || f < target) {
          inner(a + 1, b + 1)
        } else {
          None
        }
      }

      inner(0, -amb)
    }

    @tailrec
    def findFirstAB(ambs: List[Int]): (Int, Int) = {
      ambs match {
        case amb :: rest =>
          findAB(amb) match {
            case Some((a, b)) => (a, b)
            case None => findFirstAB(rest)
          }
        case Nil =>
          throw new Error()
      }
    }

    out.println(findFirstAB(ambs) match {
      case (a, b) => s"${a} ${b}"
    })


    out.flush()
  }
}