prithivMLmods/Coder-Stat huggingface dataset:
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int64_t x;
  cin >> x;

  int64_t rootx = 0;
  while (rootx * rootx <= x) {
    rootx++;
  }

  rootx--;

  vector<int64_t> factors(0);

  for (int64_t i = 1; i <= rootx; i++) {
    if (x % i == 0) {
      factors.push_back(i);
      if (i != x / i) {
        factors.push_back(x / i);
      }
    }
  }

  int64_t a = 1;
  int64_t b = 0;

  int64_t size = int64_t(factors.size());
  for (int64_t i = 0; i < size; i++) {
    int64_t d = factors.at(i);

    int64_t flag = 1;

    int64_t tmp = 0;

    while (tmp - d < 120) {
      if (tmp * tmp * tmp * tmp * tmp -
              (tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) ==
          x) {
        a = tmp;
        b = a - d;
        flag = 0;
        break;
      }

      else {
        tmp++;
      }
    }

    if (flag == 0) {
      break;
    }
  }

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

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

int main() {

  int64_t x;
  cin >> x;

  int64_t rootx = 0;
  while (rootx * rootx <= x) {
    rootx++;
  }

  rootx--;

  vector<int64_t> factors(0);

  for (int64_t i = 1; i <= rootx; i++) {
    if (x % i == 0) {
      factors.push_back(i);
      if (i != x / i) {
        factors.push_back(x / i);
      }
    }
  }

  int64_t a = 1;
  int64_t b = 0;

  int64_t size = int64_t(factors.size());
  for (int64_t i = 0; i < size; i++) {
    int64_t d = factors.at(size - 1 - i);

    int64_t flag = 1;

    int64_t tmp = 0;

    while (tmp - d < 120) {
      if (tmp * tmp * tmp * tmp * tmp -
              (tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) ==
          x) {
        a = tmp;
        b = a - d;
        flag = 0;
        break;
      }

      else {
        tmp++;
      }
    }

    if (flag == 0) {
      break;
    }
  }

  cout << a << " " << b << endl;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, a, b) for (int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

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

  ll aa, bb;
  for (ll a = 0; a < 5000; a++)
    for (ll b = -5000; b < 5000; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        aa = a, bb = b;
        break;
      }
    }

  cout << aa << " " << bb << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, a, b) for (int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

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

  ll aa, bb;
  for (ll a = 0; a < 1000; a++)
    for (ll b = -1000; b < 1000; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        aa = a, bb = b;
        break;
      }
    }

  cout << aa << " " << bb << endl;
}
Problem p02690 (C++)

Buggy submission (status: Runtime Error):
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc166_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000

int main() {
  ll x;
  scanf("%lld", &x);
  for (ll a = -100; a <= 100; a++) {
    for (ll b = -100; b <= 100; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        printf("%lld %lld\n", a, b);
        return 0;
      }
    }
  }
  assert(false);
}


Fixed submission:
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc166_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000

int main() {
  ll x;
  scanf("%lld", &x);
  ll l = 2000;
  for (ll a = 0; a <= l; a++) {
    for (ll b = -l; b <= l; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        printf("%lld %lld\n", a, b);
        return 0;
      }
    }
  }
  assert(false);
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll f(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);
}

vector<ll> divisor(ll N) {
  vector<ll> res;
  for (ll i = 1L; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      ll j = N / i;
      if (j != i) {
        res.push_back(j);
      }
    }
  }
  sort(res.begin(), res.end());
  return res;
}

void solve() {
  ll X;
  cin >> X;
  auto divisors = divisor(X);
  for (ll d : divisors) {
    ll ano = X / d;
    rep2(a, -d, d + 1) {
      ll b = a - d;
      if (f(a, b) == ano) {
        cout << a << " " << b << '\n';
        return;
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll f(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);
}

vector<ll> divisor(ll N) {
  vector<ll> res;
  for (ll i = 1L; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      ll j = N / i;
      if (j != i) {
        res.push_back(j);
      }
    }
  }
  sort(res.begin(), res.end());
  return res;
}

void solve() {
  ll X;
  cin >> X;
  auto divisors = divisor(X);
  for (ll d : divisors) {
    ll ano = X / d;
    rep2(a, -140, 140 + 1) {
      ll b = a - d;
      if (f(a, b) == ano) {
        cout << a << " " << b << '\n';
        return;
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define pr(x) cout << x << endl;
#define pr2(x, y) cout << x << " " << y << endl;
#define pr3(x, y, z) cout << x << " " << y << endl;
#define prv(v)                                                                 \
  for (auto x : v)                                                             \
    cout << x << " ";
#define ffs fflush(stdout);
#define int ll
using namespace std;

const ll N = (2e5 + 5);
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238

long long binpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;

    b >>= 1;
  }
  res %= MOD;
  return res;
}
void solve() {
  ll x;
  cin >> x;
  for (ll a = -3000; a <= 3000; a++) {
    for (ll b = -3000; b <= 3000; b++) {
      // if(a==0||b==0)continue;
      ll gg = pow(a, 5);
      ll gg2 = pow(b, 5);
      // cout<<a<<" "<<b<<" "<<gg<<" "<<gg2<<endl;
      if ((gg - gg2) == x) {

        //  cout<<gg<<" "<<gg2<<endl;
        cout << a << " " << b << endl;
        return;
      }
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  ll t = 1;
  while (t--) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define pr(x) cout << x << endl;
#define pr2(x, y) cout << x << " " << y << endl;
#define pr3(x, y, z) cout << x << " " << y << endl;
#define prv(v)                                                                 \
  for (auto x : v)                                                             \
    cout << x << " ";
#define ffs fflush(stdout);
#define int ll
using namespace std;

const ll N = (2e5 + 5);
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238

long long binpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;

    b >>= 1;
  }
  res %= MOD;
  return res;
}
void solve() {
  ll x;
  cin >> x;
  for (ll a = -1000; a <= 1000; a++) {
    for (ll b = -1000; b <= 1000; b++) {
      // if(a==0||b==0)continue;
      ll gg = pow(a, 5);
      ll gg2 = pow(b, 5);
      // cout<<a<<" "<<b<<" "<<gg<<" "<<gg2<<endl;
      if ((gg - gg2) == x) {

        //  cout<<gg<<" "<<gg2<<endl;
        cout << a << " " << b << endl;
        return;
      }
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  ll t = 1;
  while (t--) {
    solve();
  }
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <set>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

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

  cout << fixed << "no" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <set>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

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

  cout << fixed << "no" << endl;
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi = 3.1415;
ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); }
ll mini(ll a, ll b) { return (a > b ? b : a); }
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return (a % b ? gcd(a % b, b) : b);
}
ll gojou(ll n) { return pow(n, 5); }
int main() {
  ll x, ans1 = 0, ans2 = 0;
  cin >> x;
  bool f = false;
  for (ll i = -50; i < 50; i++) {
    for (ll j = -50; i < 50; j++) {
      if (gojou(i) - gojou(j) == x) {
        ans1 = i;
        ans2 = j;
        f = true;
      }
      if (f)
        break;
    }
    if (f)
      break;
  }
  cout << ans1 << " " << ans2;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi = 3.1415;
ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); }
ll mini(ll a, ll b) { return (a > b ? b : a); }
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return (a % b ? gcd(a % b, b) : b);
}
ll gojou(ll n) { return pow(n, 5); }
int main() {
  ll x, ans1 = 0, ans2 = 0;
  cin >> x;
  bool f = false;
  for (ll i = -200; i < 200; i++) {
    for (ll j = -200; j < 200; j++) {
      if (gojou(i) - gojou(j) == x) {
        ans1 = i;
        ans2 = j;
        f = true;
      }
      if (f)
        break;
    }
    if (f)
      break;
  }
  cout << ans1 << " " << ans2;
}
Problem p02690 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
template <class _T> inline void read(_T &_a) {
  bool f = 0;
  char _c = getchar();
  _a = 0;
  while (_c < '0' || _c > '9') {
    if (_c == '-')
      f = 1;
    _c = getchar();
  }
  while (_c >= '0' && _c <= '9') {
    _a = (_a << 3) + (_a << 1) - '0' + _c;
    _c = getchar();
  }
  if (f)
    _a = -_a;
}

const int MAXN = 1000002;
long long calc[71], n;

int main() {
  read(n);
  for (register long long i = 1; i <= 120; ++i)
    calc[i] = (long long)pow(i, 5);
  for (register int i = 0; i <= 120; ++i) {
    for (register int j = 0; j <= 120; ++j) {
      if (calc[i] - calc[j] == n) {
        printf("%d %d", i, j);
        return 0;
      }
      if (calc[i] + calc[j] == n) {
        printf("%d %d", i, -j);
        return 0;
      }
      if (-calc[i] - calc[j] == n) {
        printf("%d %d", -i, j);
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
template <class _T> inline void read(_T &_a) {
  bool f = 0;
  char _c = getchar();
  _a = 0;
  while (_c < '0' || _c > '9') {
    if (_c == '-')
      f = 1;
    _c = getchar();
  }
  while (_c >= '0' && _c <= '9') {
    _a = (_a << 3) + (_a << 1) - '0' + _c;
    _c = getchar();
  }
  if (f)
    _a = -_a;
}

const int MAXN = 1000002;
long long calc[1201], n;

int main() {
  read(n);
  for (register long long i = 1; i <= 120; ++i)
    calc[i] = (long long)pow(i, 5);
  for (register int i = 0; i <= 120; ++i) {
    for (register int j = 0; j <= 120; ++j) {
      if (calc[i] - calc[j] == n) {
        printf("%d %d", i, j);
        return 0;
      }
      if (calc[i] + calc[j] == n) {
        printf("%d %d", i, -j);
        return 0;
      }
      if (-calc[i] - calc[j] == n) {
        printf("%d %d", -i, j);
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  ll n;
  cin >> n;
  for (ll a = -4000; a <= 4000; a++) {
    for (ll b = -4000; b <= 4000; b++) {

      if (pow(a, 5) - pow(b, 5) == n) {
        cout << a << " " << b;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  ll n;
  cin >> n;
  for (ll a = -1000; a <= 1000; a++) {
    for (ll b = -1000; b <= 1000; b++) {

      if (pow(a, 5) - pow(b, 5) == n) {
        cout << a << " " << b;
        return 0;
      }
    }
  }
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int64_t pow(int64_t n, int64_t r) {
  int ret = 1;
  for (int i = 0; i < r; i++) {
    ret *= n;
  }
  return n;
}
int main(void) {
  int64_t X;

  cin >> X;

  for (int i = 6208; i > -6208; i--) {
    for (int j = 6208; j > -6208; j--) {
      if ((pow(i, 5) - pow(j, 5)) == X) {
        cout << i << " " << j << "\n";
        return 0;
      }
    }
  }
  return 0;
}


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

int64_t pow(int64_t n, int64_t r) {
  int ret = 1;
  for (int i = 0; i < r; i++) {
    ret *= n;
  }
  return n;
}
int main(void) {
  int64_t X;

  cin >> X;

  for (int i = 1000; i > -1000; i--) {
    for (int j = 1000; j > -1000; j--) {
      if ((pow(i, 5) - pow(j, 5)) == X) {
        cout << i << " " << j << "\n";
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
#define rep(i, l, r) for (register int i = l; i <= r; ++i)
int MAXN = 100010;
inline int read() {
  register char cc = getchar();
  register int cn(0), flus(1);
  while (cc > '9' || cc < '0') {
    if (cc == '-')
      flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    cn = cn * 10 + cc - 48;
    cc = getchar();
  }
  return cn * flus;
}
signed main() {
  int x = read();
  for (register int i = -100;; ++i) {
    for (register int j = -100; j <= 100; ++j) {
      // printf("i = %d j = %d \n",i,j);
      if (i * i * i * i * i - j * j * j * j * j == x) {
        printf("%lld %lld \n", i, j);
        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, l, r) for (register int i = l; i <= r; ++i)
int MAXN = 100010;
inline int read() {
  register char cc = getchar();
  register int cn(0), flus(1);
  while (cc > '9' || cc < '0') {
    if (cc == '-')
      flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    cn = cn * 10 + cc - 48;
    cc = getchar();
  }
  return cn * flus;
}
signed main() {
  int x = read();
  for (register int i = -1000;; ++i) {
    for (register int j = -1000; j <= 1000; ++j) {
      // printf("i = %d j = %d \n",i,j);
      if (i * i * i * i * i - j * j * j * j * j == x) {
        printf("%lld %lld \n", i, j);
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long x, a, b;
  long aa, bb;
  long i, j, k;

  cin >> x;
  for (i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      aa = 0;
      bb = 0;
      for (a = 0; a <= x; a++) {
        aa = pow(a, 5);
        bb = pow(a - i, 5);
        if (a - i <= -100000)
          continue;
        if (aa - bb == x) {
          cout << a << " " << a - i << endl;
          return 0;
        }
      }

      aa = 0;
      bb = 0;
      if (x % i == 0)
        j = x / i;
      for (a = 0; a <= x; a++) {
        aa = pow(a, 5);
        bb = pow(a - j, 5);
        if (a - j <= -100000)
          continue;
        if (aa - bb == x) {
          cout << a << " " << a - j << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long x, a, b;
  long aa, bb;
  long i, j, k;

  cin >> x;
  for (a = -120; a <= 120; a++) {
    for (b = -120; b <= 120; b++) {
      aa = pow(a, 5);
      bb = pow(b, 5);
      if (aa - bb == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++)

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

int main() {
  /*
  string s;
  cin>>s;
  if(s=="ABC")
  {
      cout<<"ARC"<<endl;
  }
  else
  {
      cout<<"ABC"<<endl;
  }
  */
  /*
   int n,k;
   cin>>n>>k;
   map <int,int> mp;
   for(int i=1;i<=k;i++)
   {
       int d;
       cin>>d;
       for(int j=1;j<=d;j++)
       {
           int a;
           cin>>a;
           mp[a]++;
       }
   }
   int count=0;
   for(int i=1;i<=n;i++)
   {
       if(mp[i]==0)
       {
           count++;
       }
   }

   cout<<count<<endl;
   */
  /*
  int n,m;
  cin>>n>>m;
  vector <pair<bool,ll>> h(n+1);  //良いか悪いか、標高
  for(int i=1;i<=n;i++)
  {
      int height;
      cin>>height;
      h[i].first=true;
      h[i].second=height;
  }

  for(int i=0;i<m;i++)
  {
      int a,b;
      cin>>a>>b;
      if(h[a].second<=h[b].second)
      {
          h[a].first = false;
      }
      if(h[a].second>=h[b].second)
      {
          h[b].first=false;
      }
  }

  int count=0;

  for(int i=1;i<=n;i++)
  {
      if(h[i].first)
      {
          count++;
      }
  }

  cout<<count<<endl;
  */

  ll x;
  cin >> x;
  for (ll i = 1; i <= x; i++) {
    if (x % i == 0) {
      ll temp = x;
      temp = x / i;
      for (ll j = 0; j <= i; j++) {
        ll a = j;
        ll b = j - i;
        if ((pow(a, 4) + pow(a, 3) * b + pow(a, 2) * pow(b, 2) + a * pow(b, 3) +
             pow(b, 4)) == temp) {
          cout << a << " " << b << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}

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

int main() {
  /*
  string s;
  cin>>s;
  if(s=="ABC")
  {
      cout<<"ARC"<<endl;
  }
  else
  {
      cout<<"ABC"<<endl;
  }
  */
  /*
   int n,k;
   cin>>n>>k;
   map <int,int> mp;
   for(int i=1;i<=k;i++)
   {
       int d;
       cin>>d;
       for(int j=1;j<=d;j++)
       {
           int a;
           cin>>a;
           mp[a]++;
       }
   }
   int count=0;
   for(int i=1;i<=n;i++)
   {
       if(mp[i]==0)
       {
           count++;
       }
   }

   cout<<count<<endl;
   */
  /*
  int n,m;
  cin>>n>>m;
  vector <pair<bool,ll>> h(n+1);  //良いか悪いか、標高
  for(int i=1;i<=n;i++)
  {
      int height;
      cin>>height;
      h[i].first=true;
      h[i].second=height;
  }

  for(int i=0;i<m;i++)
  {
      int a,b;
      cin>>a>>b;
      if(h[a].second<=h[b].second)
      {
          h[a].first = false;
      }
      if(h[a].second>=h[b].second)
      {
          h[b].first=false;
      }
  }

  int count=0;

  for(int i=1;i<=n;i++)
  {
      if(h[i].first)
      {
          count++;
      }
  }

  cout<<count<<endl;
  */

  ll A, B, 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;
      }
    }
  }

  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int mod = 1e9 + 107;
const int inf = 1e8;
int h[N];
int mx[N];
void solve() {
  ll x;
  cin >> x;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      for (ll j = -i; j <= i; j++) {
        ll b = j;
        ll a = i + j;
        ll trt = a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b +
                 b * b * b * b;
        //        cout<<i<<" "<<a<<" "<<b<<" "<<a-b<<" "<<trt<<"
        //        "<<trt*(a-b)<<endl;
        if (trt == x / i) {
          cout << a << " " << b << endl;
          return;
        }
      }
    }
  }
  exit(-1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //    cin>>t;
  while (t--)
    solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int mod = 1e9 + 107;
const int inf = 1e8;
int h[N];
int mx[N];
void solve() {
  ll x;
  cin >> x;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      for (ll j = -300; j <= 300; j++) {
        ll b = j;
        ll a = i + j;
        ll trt = a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b +
                 b * b * b * b;
        //        cout<<i<<" "<<a<<" "<<b<<" "<<a-b<<" "<<trt<<"
        //        "<<trt*(a-b)<<endl;
        if (trt == x / i) {
          cout << a << " " << b << endl;
          return;
        }
      }
    }
  }
  exit(-1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //    cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

  long long int A = 0, B = 0;

  if (X == 1) {
    cout << 1 << " " << 0 << endl;
  } else {
    int f = 0;
    for (int i = 10000; i >= -10000; --i) {
      for (int j = 9999; j >= -10000; --j) {
        A = pow(i, 5);
        B = pow(j, 5);

        if ((A - B) == X || (A + B == X)) {
          f = 1;
          if (A - B == X) {
            A = i;
            B = j;
          } else {
            A = i;
            B = -j;
          }
          break;
        }
      }
      if (f == 1) {
        break;
      }
    }

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

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

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

  long long int A = 0, B = 0;

  if (X == 1) {
    cout << 1 << " " << 0 << endl;
  } else {
    int f = 0;
    for (int i = 1000; i >= -1000; --i) {
      for (int j = 999; j >= -1000; --j) {
        A = pow(i, 5);
        B = pow(j, 5);

        if ((A - B) == X || (A + B == X)) {
          f = 1;
          if (A - B == X) {
            A = i;
            B = j;
          } else {
            A = i;
            B = -j;
          }
          break;
        }
      }
      if (f == 1) {
        break;
      }
    }

    cout << A << " " << B << endl;
  }
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main() {
  int x;
  std::cin >> x;
  for (ll i = -10000; i <= 10000; i++) {
    for (ll j = 10000; j >= -10000; j--) {
      ll a = pow(i, 5), b = pow(j, 5);
      if (a - b == (ll)x) {
        std::cout << i << ' ' << j << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main() {
  int x;
  std::cin >> x;
  for (ll i = -1000; i <= 1000; i++) {
    for (ll j = 1000; j >= -1000; j--) {
      ll a = pow(i, 5), b = pow(j, 5);
      if (a - b == (ll)x) {
        std::cout << i << ' ' << j << '\n';
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  for (int i = 1; i <= 10000; i++)
    for (int j = 0; j <= i; j++) {
      if (pow(i, 5) + pow(j, 5) == x) {
        printf("%d %d", i, -j);
        return 0;
      }
    }
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  for (int i = 1; i <= 1000; i++)
    for (int j = -1000; j <= i; j++) {
      if (pow(i, 5) + pow(j, 5) == x) {
        printf("%d %d", i, -j);
        return 0;
      }
    }
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define all(n) n.begin(), n.end()
#define yn(x) cout << (x ? "Yes" : "No") << endl;

ll gozyou(ll n) {
  ll a = 1;
  rep1(i, 5) a *= n;
  return a;
}

int main() {
  ll x, a, b;
  cin >> x;
  rep(i, 1000) rep1(k, x) {
    if (x % k == 0 && gozyou(i) - gozyou(i - x / k) == x) {
      a = i;
      b = i - x / k;
      break;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define all(n) n.begin(), n.end()
#define yn(x) cout << (x ? "Yes" : "No") << endl;

ll gozyou(ll n) {
  ll a = 1;
  rep1(i, 5) a *= n;
  return a;
}

int main() {
  ll x, a, b;
  cin >> x;
  for (ll i = -199; i < 200; i++) {
    for (ll k = -199; k < 200; k++) {

      if (gozyou(i) - gozyou(k) == x) {
        a = i;
        b = k;
        break;
      }
    }
  }
  cout << a << " " << b << endl;
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
i64 p5(i64 x) { return x * x * x * x * x; }

int main(void) {
  i64 x;
  cin >> x;
  vi P5(68);
  for (i64 i = 1; i < 68; i++)
    P5[i] = p5(i);
  for (i64 a = 1; true; a++) {
    i64 a5 = P5[a];
    for (i64 b = -a; b < a; b++) {
      i64 b5 = (b < 0 ? -P5[-b] : P5[b]);
      if (a5 - b5 == x) {
        cout << a << ' ' << b << '\n';
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
i64 p5(i64 x) { return x * x * x * x * x; }

int main(void) {
  i64 x;
  cin >> x;
  vi P5(120);
  for (i64 i = 1; i < 120; i++)
    P5[i] = p5(i);
  for (i64 a = 1; true; a++) {
    i64 a5 = P5[a];
    for (i64 b = -a; b < a; b++) {
      i64 b5 = (b < 0 ? -P5[-b] : P5[b]);
      if (a5 - b5 == x) {
        cout << a << ' ' << b << '\n';
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#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>;
ll f(ll A, ll B) { return A * A * A * A * A - B * B * B * B * B; }
int main() {
  ll x;
  cin >> x;
  map<ll, P> mp;
  for (ll A = -1000; A <= 1000; A++) {
    for (ll B = -1000; B <= 1000; B++) {
      mp[f(A, B)] = (P){A, B};
    }
  }
  printf("%d %d\n", mp[x].first, mp[x].second);
}


Fixed submission:
#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>;
ll f(ll A, ll B) { return A * A * A * A * A - B * B * B * B * B; }
int main() {
  ll x;
  cin >> x;
  map<ll, P> mp;
  for (ll A = -500; A <= 500; A++) {
    for (ll B = -500; B <= 500; B++) {
      mp[f(A, B)] = (P){A, B};
    }
  }
  printf("%d %d\n", mp[x].first, mp[x].second);
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long X, A, B;
  cin >> X;
  for (A = 0; A <= 100000; A++) {
    for (B = -A; B <= 0; B++) {
      if (pow(A, 5) - pow(B, 5) == X) {
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long X, A, B;
  cin >> X;
  for (A = -150; A <= 150; A++) {
    for (B = -150; B <= 150; B++) {
      if (pow(A, 5) - pow(B, 5) == X) {
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
}
Problem p02690 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int n, x, m, a, b, c, k;
int main() {
  for (cin >> x, a = -118; a < 120; a++) {
    ll a5 = pow(a, 5);
    for (b = -119; b < 119; b++) {
      ll b5 = pow(b, 5);
      if (a5 - b5 == x)
        return printf("%d %d", a, b);
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int n, x, m, a, b, c, k;
int main() {
  for (cin >> x, a = -118; a < 120; a++) {
    ll a5 = pow(a, 5);
    for (b = -119; b < 119; b++) {
      ll b5 = pow(b, 5);
      if (a5 - b5 == x) {
        printf("%d %d", a, b);
        return 0;
      }
    }
  }
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int X;
  cin >> X;
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 100; j++)
      if (i * i * i * i * i + j * j * j * j * j == X) {
        cout << i << ' ' << 0 - j << endl;
        return 0;
      }
  for (int i = 1;; i++) {
    for (int j = 1; j >= 0; j--) {
      if (i * i * i * i * i - j * j * j * j * j == X) {
        cout << i << ' ' << j << endl;
        return 0;
      }
      if (i * i * i * i * i - j * j * j * j * j >= X)
        break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int X;
  cin >> X;
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 100; j++)
      if (i * i * i * i * i + j * j * j * j * j == X) {
        cout << i << ' ' << 0 - j << endl;
        return 0;
      }
  for (int i = 1;; i++) {
    for (int j = i; j >= 0; j--) {
      if (i * i * i * i * i - j * j * j * j * j == X) {
        cout << i << ' ' << j << endl;
        return 0;
      }
      if (i * i * i * i * i - j * j * j * j * j >= X)
        break;
    }
  }
}
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) {}
};

// using Graph = vector<vector<Edge>>
using Graph = vector<vector<int>>;

// header area

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

  // long long A, B;
  long long ans = 0;

  long long n = 5000;

  for (long long B = -n; B < n; B++) {
    for (long long A = B; A < n; A++) {
      ans = pow(A, 5) - pow(B, 5);
      if (ans == X) {
        cout << A << " " << B;
        return 0;
      }
    }
  }
  cout << "nothing";
}

Fixed submission:
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) {}
};

// using Graph = vector<vector<Edge>>
using Graph = vector<vector<int>>;

// header area

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

  // long long A, B;
  long long ans = 0;

  long long n = 1000;

  for (long long B = -n; B < n; B++) {
    for (long long A = B; A < n; A++) {
      ans = pow(A, 5) - pow(B, 5);
      if (ans == X) {
        cout << A << " " << B;
        return 0;
      }
    }
  }
  cout << "nothing";
}
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
res = {}
for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        ans = i**5 - j**5
        res[ans] = (i, j)
n = int(input())
print(res[n][0], res[n][1])


Fixed submission:
res = {}
for i in range(-500, 500):
    for j in range(-500, 500):
        ans = i**5 - j**5
        res[ans] = (i, j)
n = int(input())
print(res[n][0], res[n][1])
Problem p02690 (C++)

Buggy submission (status: 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;
  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;
}

Fixed submission:
#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;
}
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
x = int(input())
a = 0
b = 0
for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if (i**5) - (j**5) == x:
            a = i
            b = j
            break
print("{} {}".format(a, b))


Fixed submission:
x = int(input())
a = 0
b = 0
for i in range(-500, 500):
    for j in range(-500, 500):
        if (i**5) - (j**5) == x:
            a = i
            b = j
            break
print("{} {}".format(a, b))
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
x = int(input())
a, b = 0, 0
nx = "a"
while True:
    if a**5 - b**5 == x:
        print("{} {}".format(a, b))
        break
    if -(a**5) - b**5 == x:
        print("{} {}".format(-a, b))
        break
    if a**5 - (-b) ** 5 == x:
        print("{} {}".format(a, -b))
        break
    if -(a**5) - (-b) ** 5 == x:
        print("{} {}".format(-a, -b))
        break
    if nx == "a":
        a += 1
        nx = "b"
    else:
        b += 1
        nx = "a"


Fixed submission:
x = int(input())
for b in range(1000):
    for a in range(1000):
        if a**5 - b**5 == x:
            print("{} {}".format(a, b))
            exit()
        if (-a) ** 5 - b**5 == x:
            print("{} {}".format(-a, b))
            exit()
        if a**5 - (-b) ** 5 == x:
            print("{} {}".format(a, -b))
            exit()
        if (-a) ** 5 - (-b) ** 5 == x:
            print("{} {}".format(-a, -b))
            exit()
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

x = int(input())

for i in range(-2000, 2000):
    for j in range(-2000, 2000):
        if i**5 - j**5 == x:
            print(i, j)
            sys.exit()


Fixed submission:
import sys

x = int(input())

for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i**5 - j**5 == x:
            print(i, j)
            sys.exit()
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
X = int(input())

# for b in range(65, -64, -1):
for b in range(1000000, -1000000, -1):
    a = (X + b**5) ** 0.2
    # print('b a', b, a)
    if type(a) == complex:
        if a.imag != 0:
            continue
        print(int(a.real), b)
        exit()
    elif a.is_integer():
        print(int(a), b)
        exit()

for a in range(1000000, -1000000, -1):
    b = (X - a**5) ** 0.2
    # print('b a', b, a)
    if type(b) == complex:
        if b.imag != 0:
            continue
        print(int(b.real), a)
        exit()
    elif b.is_integer():
        print(int(a), b)
        exit()


Fixed submission:
X = int(input())

for a in range(-1000, 1000):
    for b in range(-1000, 1000):
        if a**5 - b**5 == X:
            print(a, b)
            exit()
Problem p02690 (Python)

Buggy submission (status: Runtime Error):
"""
A^5 - B^5
= (A - B)(A^4 + A^3*B + A^2*B^2 + A*B^3 + B^4)
= (A - B){(A + B) * (A^3 + B^3) + A^2*B^2}
= (A - B){(A + B)^2 * (A^2 - AB + B^2) + A^2*B^2}

-> (A + B)^2 > 1, (A^2 - AB + B^2) > 1, A^2*B^2 > 1.
"""


def main():
    print(*solve())


def solve():
    X = int(input())

    for a in range(-100, 100):
        for b in range(-100, 100):
            if a**5 - b**5 == X:
                return a, b


if __name__ == "__main__":
    main()


Fixed submission:
"""
A^5 - B^5
= (A - B)(A^4 + A^3*B + A^2*B^2 + A*B^3 + B^4)
= (A - B){(A + B) * (A^3 + B^3) + A^2*B^2}
= (A - B){(A + B)^2 * (A^2 - AB + B^2) + A^2*B^2}

-> (A + B)^2 > 1, (A^2 - AB + B^2) > 1, A^2*B^2 > 1.
"""


def main():
    print(*solve())


def solve():
    X = int(input())

    for a in range(-1000, 1000):
        for b in range(-1000, 1000):
            if a**5 - b**5 == X:
                return a, b


if __name__ == "__main__":
    main()
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
X = int(input())

CNT = 2000

for a in range(-CNT, CNT):
    for b in range(-CNT, CNT):
        if X == a**5 - b**5:
            print(a, b)
            exit()


Fixed submission:
X = int(input())

CNT = 500

for a in range(-CNT, CNT):
    for b in range(-CNT, CNT):
        if X == a**5 - b**5:
            print(a, b)
            exit()
Problem p02690 (Python)

Buggy submission (status: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(1000):
    my_dict[i**5] = i

for i in range(-1000, 1000):
    target = x + (i**5)
    if (-target) in my_dict:
        print(-my_dict[target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()


Fixed submission:
x = int(input())

my_dict = dict()

for i in range(1000):
    my_dict[i**5] = i

for i in range(-1000, 1000):
    target = x + (i**5)
    if (-target) in my_dict:
        print(-my_dict[-target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
X = int(input())
a = 1
flug = True
while flug:
    b = -119
    while b <= 118:
        if a**5 - b**5 == X:
            print(a, b)
            flug = False
            break
        else:
            b += 1


Fixed submission:
X = int(input())
a = 1
flug = True
while flug:
    b = -119
    while b <= 118:
        if a**5 - b**5 == X:
            print(a, b)
            flug = False
            break
        else:
            b += 1
    a += 1
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
def prime_factorize(n):
    """Calculate prime factorization and return unique numbers and 1."""
    ans = set()
    ans_add = ans.add
    ans_add(1)
    while n % 2 == 0:
        ans_add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            ans_add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        ans_add(n)
    return ans


def main():
    x = int(input())
    # 素因数分解してユニークな因数を取る。
    insu = prime_factorize(x)
    # a^5 - b^5 も a - b も，ある因数の倍数となる。
    # ここは a >= b と仮定すると，a は正でなくては，xが負になっちゃう。

    b_min = -int(x ** (1 / 5))
    for n in insu:
        b = b_min
        while 1:
            a = b
            while 1:
                a += n
                if a < 0:
                    continue
                cand = a**5 - b**5
                if cand == x:
                    return f"{a} {b}"
                elif cand > x:
                    break
            b += 1


if __name__ == "__main__":
    print(main())


Fixed submission:
def prime_factorize(n):
    """Calculate prime factorization and return unique numbers and 1."""
    ans = set()
    ans_add = ans.add
    ans_add(1)
    while n % 2 == 0:
        ans_add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            ans_add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        ans_add(n)
    return ans


def main():
    x = int(input())
    # 素因数分解してユニークな因数を取る。
    insu = prime_factorize(x)
    # a^5 - b^5 も a - b も，ある因数の倍数となる。
    # ここは a >= b と仮定すると，a は正でなくては，xが負になっちゃう。

    b_min = -int(x ** (1 / 5))
    for n in insu:
        b = b_min
        while 1:
            a = b
            while 1:
                a += n
                if a < 0:
                    continue
                cand = a**5 - b**5
                if cand == x:
                    return f"{a} {b}"
                elif cand > x:
                    break
            b += 1
            if (b + n) ** 5 - b**5 > x:
                break


if __name__ == "__main__":
    print(main())
Problem p02690 (Python)

Buggy submission (status: Runtime Error):
x = int(input())

rs = [i**5 for i in range(300)]

for r in rs:
    if (x - r) in rs:
        print(rs.index(r), -rs.index(x - r))
    elif (x + r) in rs:
        print(rs.index(r), rs.index(x - r))
    else:
        continue
    break


Fixed submission:
x = int(input())

rs = [i**5 for i in range(300)]

for r in rs:
    if r <= x:
        if x - r in rs:
            print(rs.index(r), -rs.index(x - r))
            break
    if r > x:
        if r - x in rs:
            print(rs.index(r), rs.index(r - x))
            break
Problem p02690 (Python)

Buggy submission (status: Runtime Error):
x = int(input())
for i in range(x // 2 + 1):
    if pow(x - pow(i, 5), 1 / 5).is_integer():
        print(i, int(-pow(x - pow(i, 5), 1 / 5)))
        exit()


Fixed submission:
import numpy as np


def main():
    x = int(input())
    A = np.arange(-120, 120)
    a = A**5
    for i, a_1 in enumerate(a):
        for j, a_2 in enumerate(a):
            if a_1 - a_2 == x:
                print(A[i], A[j])
                return


if __name__ == "__main__":
    main()
Problem p02690 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 0; i < 1000000000; i++) {
    for (int j = i - 1; (i * i * i * i * i) - (j * j * j * j * j) > 0; j--) {
      long long num = (i * i * i * i * i) - (j * j * j * j * j);
      if (num == N) {
        ans1 = i;
        ans2 = j;
        break;
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
}


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

int main() {
  long long N;
  cin >> N;
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 0; i < 5000000; i++) {
    for (int j = i - 1; (i * i * i * i * i) - (j * j * j * j * j) > 0; j--) {
      long long num = (i * i * i * i * i) - (j * j * j * j * j);
      if (num == N) {
        ans1 = i;
        ans2 = j;
        break;
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
}
Problem p02690 (Python)

Buggy submission (status: Time Limit Exceeded):
x = int(input())
a = int(x**0.2)
b = 0
while a**5 - b**5 != x:
    b -= 1
print(a, b)


Fixed submission:
x = int(input())
for a in range(-1000, 1000):
    for b in range(-1000, 1000):
        if a**5 - b**5 == x:
            print(a, b)
            quit()
Problem p02691 (C++)

Buggy submission (status: Time Limit Exceeded):
#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() {
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  int ans = 0;
  rep(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      if (j - i == A[i] + A[j])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#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() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  ll ans = 0;
  rep(i, n) {
    int sa = i - a[i];
    // i<j  j-i==Ai+Aj  Ai+i==j-Aj  Ai+iはmpに入れていくと計算時間を減らせる
    ans += mp[sa];
    int wa = a[i] + i;
    mp[wa]++;
  }
  cout << ans << endl;
  return 0;
}