Problem p02690 (C++) — buggy submission, verdict: Runtime Error

// #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna> using akari = vector<kizuna>;
template <class yuzuki> using yukari = akari<akari<yuzuki>>;
template <class tsurumaki> using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha> using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

vector<pair<i64, int>> factorize(i64 x) {
  vector<pair<i64, int>> res;
  for (i64 f = 2; f * f <= x; f++) {
    if (x % f) {
      continue;
    }
    int cnt = 0;
    while (x % f == 0) {
      cnt++;
      x /= f;
    }
    res.push_back(make_pair(f, cnt));
  }
  if (x > 1) {
    res.push_back(make_pair(x, 1));
  }
  return res;
}

//------------------------------- Dubug Functions ---------------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve() {
  i64 x;
  cin >> x;
  for (i64 a = -120; a < 120; a++)
    for (i64 b = -120; b < 120; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        cout << a << ' ' << b << endl;
        return;
      }
    }
}

int main() {
  solve();
  return 0;
}


Error: WA

Fixed submission:

// #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna> using akari = vector<kizuna>;
template <class yuzuki> using yukari = akari<akari<yuzuki>>;
template <class tsurumaki> using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha> using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

vector<pair<i64, int>> factorize(i64 x) {
  vector<pair<i64, int>> res;
  for (i64 f = 2; f * f <= x; f++) {
    if (x % f) {
      continue;
    }
    int cnt = 0;
    while (x % f == 0) {
      cnt++;
      x /= f;
    }
    res.push_back(make_pair(f, cnt));
  }
  if (x > 1) {
    res.push_back(make_pair(x, 1));
  }
  return res;
}

//------------------------------- Dubug Functions ---------------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve() {
  i64 x;
  cin >> x;
  auto fs = factorize(x);
  for (auto &p : fs) {
    for (int j = 0; j < 2; j++) {
      i64 cur = j ? -1 : 1;
      for (int i = 0; i <= p.second; i++) {
        for (i64 b = -3030; b <= 3030; b++) {
          i64 a = b + cur;
          if (pow(a, 5) - pow(b, 5) == x) {
            cout << a << ' ' << b << endl;
            return;
          }
        }
        cur *= p.first;
      }
    }
  }
  exit(1);
}

int main() {
  solve();
  return 0;
}