alexjercan/bugnet huggingface dataset:
Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

constexpr long long INF = (1LL << 12);

long long f(long long x) { return (x * x * x * x * x); }

long long calc(long long x) {
  long long l = -INF, r = INF;
  while (abs(l - r) > 1) {
    long long mid = (l + r) / 2;
    if (f(mid) <= x)
      l = mid;
    else
      r = mid;
  }
  return l;
}

int main() {
  long long n;
  cin >> n;

  auto is_five = [&](long long x) {
    long long l = -INF, r = INF;
    while (abs(l - r) > 1) {
      long long mid = (l + r) / 2;
      if (f(mid) <= x)
        l = mid;
      else
        r = mid;
    }
    return (f(l) == x);
  };

  long long a, b;
  for (long long i = -INF; i <= INF; i++) {
    long long j = f(i) + n;
    if (is_five(j)) {
      a = calc(j);
      b = i;
      break;
    }
  }
  assert(f(a) - f(b) == n);
  cout << a << ' ' << b << '\\n';
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

constexpr long long INF = (1LL << 12);

long long f(long long x) { return (x * x * x * x * x); }

int main() {
  long long n;
  cin >> n;

  auto is_five = [&](long long x) {
    long long l = -INF, r = INF;
    while (abs(l - r) > 1) {
      long long mid = (l + r) / 2;
      if (f(mid) <= x)
        l = mid;
      else
        r = mid;
    }
    return (f(l) == x);
  };

  long long a, b;
  for (long long i = -INF; i <= INF; i++) {
    long long j = f(i) + n;
    if (is_five(j)) {
      a = j;
      b = i;
      break;
    }
  }
  assert(f(a) - f(b) == n);
  cout << a << ' ' << b << '\\n';
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {

  long long X;

  scanf("%lld", &X);

  for (int i = -118; i <= 119; i++) {
    for (int j = -118; j <= 119; j++) {
      if ((pow(i, 5) - pow(j, 5)) == X) {
        printf("%d %d\\n", i, j);
        return 0;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  long long X;

  scanf("%lld", &X);

  for (int i = -1; i <= X; i++) {
    for (int j = -1; j <= X; j++) {
      if ((pow(i, 5) - pow(j, 5)) == X) {
        printf("%d %d\\n", i, j);
        return 0;
      }
    }
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  ll x;
  cin >> x;
  ll max = 1e17;
  ll mi_max = -1e17;
  for (ll i = 0; ll(pow(i, 5)) < max; i++) {
    for (ll j = 2000; ll(pow(j, 5)) > mi_max; j--) {
      if (ll(pow(i, 5)) - ll(pow(j, 5)) == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  ll x;
  cin >> x;
  ll max = 1e18;
  ll mi_max = -1e18;
  for (ll i = 0; ll(pow(i, 5)) < max; i++) {
    for (ll j = 0; ll(pow(j, 5)) > mi_max; j--) {
      if (ll(pow(i, 5)) - ll(pow(j, 5)) == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  cin >> a;
  int n, m;
  for (n = -119; n < 120; n++) {
    for (m = -119; m < 120; m++) {
      if (pow(n, 5) - pow(m, 5) == a) {
        cout << n << " " << m << endl;
        return 0;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  cin >> a;
  vector<int> yaku;
  for (int i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      yaku.push_back(i);
      if (i * i != a)
        yaku.push_back(a / i);
    }
  }
  for (int i = 0; i < int(yaku.size()); i++) {
    for (int j = -a; j < a; j++) {
      if (pow(j, 5) - pow(j - yaku[i], 5) == a) {
        cout << j << " " << j - yaku[i] << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

long long fifth(long long A) { return A * A * A * A * A; }

int main() {

  long long X;
  cin >> X;

  long long A = 1;
  map<long long, long long> m;
  m.insert(make_pair(0, 0));

  while (true) {
    m.insert(make_pair(fifth(A), A));
    decltype(m)::iterator it = m.find(fifth(A) - X);
    if (it != m.end()) {
      cout << A << " " << m[fifth(A) - X] << endl;
      return 0;
    }
    it = m.find(X - fifth(A));
    if (it != m.end()) {
      cout << A << " " << m[X - fifth(A)] * (-1) << endl;
      return 0;
    }
    A++;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

long long fifth(long long A) { return A * A * A * A * A; }

int main() {

  long long X;
  cin >> X;

  long long A = 1;

  while (true) {
    long long rest = abs(fifth(A) - X);
    long long B = 0;
    while (fifth(B) <= rest)
      B++;
    B--;
    if (fifth(A) - fifth(B) == X) {
      cout << A << " " << B << endl;
      return 0;
    } else if (fifth(A) + fifth(B) == X) {
      cout << A << " " << B * (-1) << endl;
      return 0;
    }
  }

  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

ll pibot;

ll nibutan(ll l, ll u, ll search_num) {
  //	cout<<"nsn"<<search_num<<endl;
  ll low = l;
  ll up = u;

  pibot = (low + up) / 2;
  //	cout<<"a"<<endl;
  while (low < up) {
    pibot = (low + up) / 2;
    // cout<<pibot<<endl;
    //		if(abs(pibot) > 8000){//8192
    //			return 0;
    //		}
    ll number = pibot * pibot * pibot * pibot * pibot;
    //		cout<<"num : "<<number<<endl;
    if (number == search_num) {
      return 1;
    } else if (number < search_num) {
      low = pibot + 1;
    } else {
      up = pibot - 1;
    }
    //		cout<<low<<" "<<up<<endl;
  }
  return 0;
}

int main() {
  ll X;
  ll A, B;
  cin >> X;
  ll ans;
  ll i = 0;
  while (i < INT_MAX) {
    // assert(i < 2);
    ll sn = X + i * i * i * i * i;
    A = nibutan(-200, 200, sn);
    if (A != 0) {
      A = pibot;
      B = i;
      break;
    }
    sn = X - i * i * i * i * i;
    // cout<<"sn"<<sn<<endl;
    A = nibutan(-200, 200, sn);
    if (A != 0) {
      A = pibot;
      B = -i;
      break;
    }
    i++;
  }

  cout << A << " " << B << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

ll pibot;

ll nibutan(ll l, ll u, ll search_num) {
  //	cout<<"nsn"<<search_num<<endl;
  ll low = l;
  ll up = u;

  pibot = (low + up) / 2;
  //	cout<<"a"<<endl;
  while (low < up) {
    pibot = (low + up) / 2;
    // cout<<pibot<<endl;
    //		if(abs(pibot) > 8000){//8192
    //			return 0;
    //		}
    ll number = pibot * pibot * pibot * pibot * pibot;
    //		cout<<"num : "<<number<<endl;
    if (number == search_num) {
      return 1;
    } else if (number < search_num) {
      low = pibot + 1;
    } else {
      up = pibot - 1;
    }
    //		cout<<low<<" "<<up<<endl;
  }
  return 0;
}

int main() {
  ll X;
  ll A, B;
  cin >> X;
  ll ans;
  ll i = 0;
  while (i < INT_MAX) {
    // assert(i < 2);
    ll sn = X + i * i * i * i * i;
    A = nibutan(-8200, 8200, sn);
    if (A != 0) {
      A = pibot;
      B = i;
      break;
    }
    sn = X - i * i * i * i * i;
    // cout<<"sn"<<sn<<endl;
    A = nibutan(-8200, 8200, sn);
    if (A != 0) {
      A = pibot;
      B = -i;
      break;
    }
    i++;
  }

  cout << A << " " << B << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

ll pibot;

ll nibutan(ll l, ll u, ll search_num) {
  //	cout<<"nsn"<<search_num<<endl;
  ll low = l;
  ll up = u;

  pibot = (low + up) / 2;
  //	cout<<"a"<<endl;
  while (low < up) {
    pibot = (low + up) / 2;
    // cout<<pibot<<endl;
    //		if(abs(pibot) > 8000){//8192
    //			return 0;
    //		}
    ll number = pibot * pibot * pibot * pibot * pibot;
    //		cout<<"num : "<<number<<endl;
    if (number == search_num) {
      return 1;
    } else if (number < search_num) {
      low = pibot + 1;
    } else {
      up = pibot - 1;
    }
    //		cout<<low<<" "<<up<<endl;
  }
  return 0;
}

int main() {
  ll X;
  cin >> X;
  ll ans;
  ll i = 0;

  ll ansA, ansB;

  for (ll A = -8000; A <= 8000; A++) {
    for (ll B = -8000; B <= 8000; B++) {
      ll sum = A * A * A * A * A - B * B * B * B * B;
      if (sum == X) {
        ansA = A;
        ansB = B;
        break;
      }
    }
  }

  cout << ansA << " " << ansB << endl;
  return 0;
  //	ll A,B;
  //	while(i < INT_MAX){
  //		//assert(i < 2);
  //		ll sn = X + i*i*i*i*i;
  //		A = nibutan(-1000,1000,sn);
  //		if(A != 0){
  //			A = pibot;
  //			B = i;
  //			break;
  //		}
  //		sn = X - i*i*i*i*i;
  //		//cout<<"sn"<<sn<<endl;
  //		A = nibutan(-1000,1000,sn);
  //		if(A != 0){
  //			A = pibot;
  //			B = -i;
  //			break;
  //		}
  //		i++;
  //	}

  //	cout<<A<<" "<<B<<endl;
  //	return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

ll pibot;

ll nibutan(ll l, ll u, ll search_num) {
  //	cout<<"nsn"<<search_num<<endl;
  ll low = l;
  ll up = u;

  pibot = (low + up) / 2;
  //	cout<<"a"<<endl;
  while (low < up) {
    pibot = (low + up) / 2;
    // cout<<pibot<<endl;
    //		if(abs(pibot) > 8000){//8192
    //			return 0;
    //		}
    ll number = pibot * pibot * pibot * pibot * pibot;
    //		cout<<"num : "<<number<<endl;
    if (number == search_num) {
      return 1;
    } else if (number < search_num) {
      low = pibot + 1;
    } else {
      up = pibot - 1;
    }
    //		cout<<low<<" "<<up<<endl;
  }
  return 0;
}

int main() {
  ll X;
  ll A, B;
  cin >> X;
  ll ans;
  ll i = 0;
  while (i < INT_MAX) {
    // assert(i < 2);
    ll sn = X + i * i * i * i * i;
    A = nibutan(-1000, 1000, sn);
    if (A != 0) {
      A = pibot;
      B = i;
      break;
    }
    sn = X - i * i * i * i * i;
    // cout<<"sn"<<sn<<endl;
    A = nibutan(-1000, 1000, sn);
    if (A != 0) {
      A = pibot;
      B = -i;
      break;
    }
    i++;
  }

  cout << A << " " << B << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

// Bismillah hirrahmanir Rahim
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define dbug printf("I am here\\n");
#define Fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
const int m = 10e6;
using namespace std;

int main() {
  long long int a, b, tst, n, k;
  cin >> n;
  if (n == 1) {
    cout << 0 << " "
         << "-1" << endl;
    return 0;
  }
  for (int i = -200; i <= 200; i++) {
    for (int j = -200; j <= 200; j++) {

      if ((i * i * i * i * i) - (j * j * j * j * j) == n) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

// Bismillah hirrahmanir Rahim
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define dbug printf("I am here\\n");
#define Fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
const int m = 10e6;
using namespace std;

int main() {
  long long int a, b, tst, n, k;
  cin >> n;
  int i;
  for (i = 0;; i++) {
    b = pow(i, 5);
    if (b + 1 == n)
      break;
  }
  cout << i << " "
       << "-1" << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#include <iostream>
using namespace std;
int main() {
  int64_t x;
  cin >> x;
  int64_t a, b;
  bool is_end = false;
  for (int64_t i = -118; i < 119; ++i) {
    auto temp = pow(i, 5);
    for (int64_t j = -119; j < i; ++j) {
      if (x == temp - pow(j, 5)) {
        a = i;
        b = j;
        is_end = true;
        break;
      }
    }
    if (is_end) {
      break;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#include <iostream>
using namespace std;
int main() {
  int64_t x;
  cin >> x;
  int ans_a, ans_b;
  bool end = false;
  for (int64_t i = 1; i <= x; ++i) {
    if (x % i == 0) {
      int64_t a = 1;
      int64_t b = a - i;
      while (true) {
        int64_t temp = i * (pow(a, 4) + pow(a, 3) * b + pow(a, 2) * pow(b, 2) +
                            a * pow(b, 3) + pow(b, 4));
        if (temp == x) {
          ans_a = a;
          ans_b = b;
          end = true;
          break;
        } else if (temp > x) {
          break;
        }
        a++;
        b++;
      }
    }
    if (end) {
      break;
    }
  }
  cout << ans_a << " " << ans_b << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;

using namespace std;

ll pow5(ll x) {
  ll xx = x * x;
  return xx * xx * x;
}

int main() {
  ll x;
  cin >> x;
  vector<ll> facts;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i)
      continue;
    facts.push_back(i);
    if (i * i != x)
      facts.push_back(x / i);
  }
  for (auto &fi : facts) {
    if (fi > 1000)
      continue;
    for (ll a = 0; true; a++) {
      ll b = a - fi;
      ll d = pow5(a) - pow5(b);
      if (d == x) {
        cout << a << ' ' << b << '\\n';
        return 0;
      } else if (b > 0 && d > x) {
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;

using namespace std;

#define fi first
#define se second

ll pow5(ll x) {
  ll xx = x * x;
  return xx * xx * x;
}

int main() {
  ll x;
  cin >> x;
  vector<ll> facts;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i)
      continue;
    facts.push_back(i);
    if (i * i != x)
      facts.push_back(x / i);
  }
  for (auto &fi : facts) {
    for (ll a = 0; true; a++) {
      ll b = a - fi;
      ll d = pow5(a) - pow5(b);
      if (d == x) {
        cout << a << ' ' << b << '\\n';
        return 0;
      } else if (b > 0 && d > x) {
        break;
      }
    }
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int, int>
#define PI 3.141592653589793
const int INF = 1001001001;

int main() {
  ll x;
  cin >> x;

  rep(ai, 10000) {
    ll aa = (ll)pow(ai, 5);
    rep(bi, 10000) {
      ll bbi = (ll)pow(bi, 5);
      if (aa - x == bbi) {
        cout << ai << " " << bi;
        return 0;
      }
      if (aa - x == -bbi) {
        cout << ai << " " << -bi;
        return 0;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int, int>
#define PI 3.141592653589793
const int INF = 1001001001;

int main() {
  ll x;
  cin >> x;

  rep(ai, INF) {
    ll aa = (ll)pow(ai, 5);
    rep(bi, 100) {
      ll bbi = (ll)pow(bi, 5);
      if (aa - x == bbi) {
        cout << ai << " " << bi;
        return 0;
      }
      if (aa - x == -bbi) {
        cout << ai << " " << -bi;
        return 0;
      }
    }
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll x;

  cin >> x;

  for (ll i = -1000; i <= 1000; i++) {
    for (ll j = -1000; j <= 1000; j++) {
      if (i * i * i * i * i - j * j * j * j * j == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll x;

  cin >> x;
  for (ll i = 1; i; i++) {
    ll mon = x - i * i * i * i * i;
    for (ll j = 0; j * j * j * j * j <= mon; j++) {
      if ((mon) == (-1) * (j * j * j * j * j)) {
        cout << i << " " << j << endl;
        return 0;
      }
      if (mon == j * j * j * j * j) {
        cout << i << " " << -1 * j << endl;
        return 0;
      }
      if (i * i * i * i * i - j * j * j * j * j > x)
        break;
    }
  }
}
Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (n / i != i)
        res.push_back(n / i);
    }
  }
  sort(all(res));
  return res;
}

ll g(ll a, ll b) {
  return a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b +
         b * b * b * b;
}

int main() {
  ll x;
  cin >> x;

  vector<ll> f = divisor(x);
  vector<ll> d = divisor(x);

  rep(i, f.size()) d.push_back(f[i] * (-1));

  ll a, b;
  for (auto e : d) {
    ll s = x / e;

    bool ok = false;

    for (ll i = -1000; i <= 1000; ++i) {
      a = e + i;
      b = i;
      ll t = g(a, b);

      if (s == t) {
        ok = true;
        break;
      }
    }

    if (ok)
      break;
  }

  cout << a << " " << b << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (n / i != i)
        res.push_back(n / i);
    }
  }
  sort(all(res));
  return res;
}

ll g(ll a, ll b) {
  return a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b +
         b * b * b * b;
}

int main() {
  ll x;
  cin >> x;

  vector<ll> f = divisor(x);
  vector<ll> d = f;

  rep(i, d.size()) d.push_back(f[i] * (-1));

  ll a, b;
  for (auto e : d) {
    ll s = x / e;

    bool ok = false;

    for (ll i = -1000; i <= 1000; ++i) {
      a = e + i;
      b = i;
      ll t = g(a, b);

      if (s == t) {
        ok = true;
        break;
      }
    }

    if (ok)
      break;
  }

  cout << a << " " << b << endl;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

/*input
1
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll x;
  cin >> x;
  for (ll a = -1000; a <= 1000; ++a) {
    for (ll b = -1000; b <= 1000; ++b) {
      ll a5 = a * a * a * a * a;
      ll b5 = b * b * b * b * b;
      if (a5 - b5 == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

/*input
33
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll pow(ll a) { return a * a * a * a * a; }

bool C(ll a, ll b, ll x) { return a - pow(b) >= x; }

bool D(ll a, ll b, ll x) { return a - pow(b) == x; }

int main() {
  ll X;
  cin >> X;
  rep(i, 1001001) {
    ll a = pow(i);
    ll lb = -1001001, ub = 1001001;
    while (lb < ub) {
      ll mid = (lb + ub) / 2;
      if (C(a, mid, X))
        lb = mid;
      else
        ub = mid;
    }
    if (D(a, ub, X)) {
      cout << i << " " << ub << endl;
      break;
    }
  }
}