Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <tuple>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define int long long
#define ull unsigned long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define f(a, b) for (int i = a; i < b; i++)
#define fr(a, b) for (int i = a - 1; i >= b; i--)
#define tr(x, m) for (auto x : m)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define unq(v) v.erase(unique(all(v)), v.end())
#define el "\\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
const ld PI = atan(1.0) * 4.0;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld EPS = 0.0000001;
const ll MD = 998244353;

int32_t main() {
  fio;
  int x;
  cin >> x;
  int xx, frt;
  int nm = pow(x, 1.0 / 5);
  //  cout<<nm<<el;
  nm++;
  for (int i = -nm;; i++) {
    xx = pow(i, 5);
    xx += x;
    frt = pow(xx, 1.0 / 5);
    if (pow(frt, 5) == xx) {
      cout << frt << " " << i << el;
      return 0;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <tuple>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define int long long
#define ull unsigned long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define f(a, b) for (int i = a; i < b; i++)
#define fr(a, b) for (int i = a - 1; i >= b; i--)
#define tr(x, m) for (auto x : m)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define unq(v) v.erase(unique(all(v)), v.end())
#define el "\\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
const ld PI = atan(1.0) * 4.0;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld EPS = 0.0000001;
const ll MD = 998244353;
int ffrt(int n) {
  if (n == 0 || n == 1)
    return n;
  int low = 1, high = n, ans = 0;
  while (low <= high) {

    int mid = (low + high) / 2;
    int mid5 = mid * mid * mid * mid * mid;
    if (mid5 == n)
      return mid;
    if (mid5 < n) {
      low = mid + 1;
      ans = mid;
    } else
      high = mid - 1;
  }
  return ans;
}
int32_t main() {
  fio;
  int x;
  cin >> x;
  int xx, frt;
  // cout<<ffrt(-32)<<el;
  int nm = ffrt(x);
  nm++;
  for (int i = -nm; i < nm; i++) {
    xx = i * i * i * i * i;
    xx += x;
    frt = ffrt(xx);
    if ((frt * frt * frt * frt * frt) == xx) {
      cout << frt << " " << i << el;
      return 0;
    }
  }
  return 0;
}