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

#include <algorithm>
#include <complex>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (int i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N)                                                      \\
  sort(A, A + N,                                                               \\
       [](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
#define endl '\\n'
#define mod 1000000007
typedef long long ll;

/*
unsigned gcd(int a, int b) {
        while (1) {
                if (a < b) swap(a, b);
                if (!b) break;
                a %= b;
        }
        return a;
}


ll comb(int n, int r) {
        if (r * 2 > n) r = n - r;
        uintmax_t dividend = 1;
        uintmax_t divisor = 1;
        for (unsigned int i = 1; i <= r; ++i) {
                dividend *= (n - i + 1);
                divisor *= i;
        }
        return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
        char *left_char = (char *)left;
        char *right_char = (char *)right;

        return strcmp(left_char, right_char);
}
*/

int main() {

  //	ios::sync_with_stdio(false);
  //	cin.tie(0);

  // int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
  ll i, j, k, l, m, n, len;
  ll C, D, N, M, K, num_R, num_G, num_B, temp;
  ll sum = 0, sum_B = 0, sum_C = 0, max, min, count = 0, Q, W, X, flag = 0;
  ll A, B, *H, *ans;

  ll temp1, temp2;

  cin >> X;

  for (i = -200; i <= 200; i++) {
    for (j = -200; j <= 200; j++) {
      if ((i * i * i * i * i - j * j * j * j * j) == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  //	cout << "nakatta" << endl;
  return 0;

} // 1 2 3 4 5 6


Error: TLE

Fixed submission:

#include <algorithm>
#include <complex>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (int i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N)                                                      \\
  sort(A, A + N,                                                               \\
       [](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
#define endl '\\n'
#define mod 1000000007
typedef long long ll;

/*
unsigned gcd(int a, int b) {
        while (1) {
                if (a < b) swap(a, b);
                if (!b) break;
                a %= b;
        }
        return a;
}


ll comb(int n, int r) {
        if (r * 2 > n) r = n - r;
        uintmax_t dividend = 1;
        uintmax_t divisor = 1;
        for (unsigned int i = 1; i <= r; ++i) {
                dividend *= (n - i + 1);
                divisor *= i;
        }
        return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
        char *left_char = (char *)left;
        char *right_char = (char *)right;

        return strcmp(left_char, right_char);
}
*/

int main() {

  //	ios::sync_with_stdio(false);
  //	cin.tie(0);

  // int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
  ll i, j, k, l, m, n, len;
  ll C, D, N, M, K, num_R, num_G, num_B, temp;
  ll sum = 0, sum_B = 0, sum_C = 0, max, min, count = 0, Q, W, X, flag = 0;
  ll A, B, *H, *ans;

  ll temp1, temp2;

  cin >> X;

  i = pow(X, 0.2);

  while (1) {
    flag = 0;
    A = i;
    B = A * A * A * A * A - X;
    if (B < 0)
      flag = 1;

    B = abs(B);

    j = pow(B, 0.2);

    if (B == j * j * j * j * j) {
      if (flag == 1)
        j *= -1;

      cout << A << " " << j << endl;
      break;
    }
  }

  return 0;

} // 1 2 3 4 5 6