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

#include <bits/stdc++.h>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (i = 1; i <= n; i++)
#define reps(i, a, n) for (i = a; i <= n; i++)
#define mem(ara, n) memset(ara, n, sizeof(ara))
#define memb(ara) memset(ara, false, sizeof(ara))
#define all(x) (x).begin(), (x).end()
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define eb emplace_back
#define em emplace
#define pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci() {
  string binary = bitset<8>(128).to_string(); // to binary
  cout << binary << "\\n";

  unsigned long decimal = bitset<8>(binary).to_ulong();
  cout << decimal << "\\n";
}

int getnum(string a) {
  int i, p = 0;
  rep0(i, a.size()) {
    p *= 10;
    p += a[i] - '0';
  }
  return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif*/
  fast

      ll a,
      x;
  cin >> a;
  for (int i = 0; i <= 100; i++) {
    x = pow(i, 5);
    if (x - i > a) {
      x = i - 1;
      break;
    }
  }
  ll x1 = pow(x, 5);
  ll x3 = a - x1;
  if (x1 == a) {
    cout << x << " " << 0 << endl;
  } else {
    for (int i = -150; i <= 150; i++) {
      for (int j = -150; j <= 150; j++) {
        ll x2 = pow(i, 5) - pow(j, 5);
        // cout<<x2<<endl;
        if (x2 == a) {
          cout << i << " " << j << endl;
          return 0;
        }
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (i = 1; i <= n; i++)
#define reps(i, a, n) for (i = a; i <= n; i++)
#define mem(ara, n) memset(ara, n, sizeof(ara))
#define memb(ara) memset(ara, false, sizeof(ara))
#define all(x) (x).begin(), (x).end()
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define eb emplace_back
#define em emplace
#define pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci() {
  string binary = bitset<8>(128).to_string(); // to binary
  cout << binary << "\\n";

  unsigned long decimal = bitset<8>(binary).to_ulong();
  cout << decimal << "\\n";
}

int getnum(string a) {
  int i, p = 0;
  rep0(i, a.size()) {
    p *= 10;
    p += a[i] - '0';
  }
  return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif*/
  fast

      ll a,
      x;
  cin >> a;
  for (int i = 0; i <= 32; i++) {
    x = pow(i, 5);
    if (x - i > a) {
      x = i - 1;
      break;
    }
  }
  ll x1 = pow(x, 5);
  if (x1 == a) {
    cout << x << " " << 0 << endl;
  } else {
    for (int i = -x; i <= x; i++) {
      ll x2 = x1 - pow(i, 5);
      // cout<<x2<<endl;
      if (x2 == a) {
        cout << x << " " << i << endl;
        return 0;
      }
    }
  }
}