Problem p02690 (C++)

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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long
#define endl "\n"

#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())      //
#define cpres(c, val) (find(all(c), val) != (c).end()) //

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

const int INF = 9e18;
// const int N = 1e9 + 7;
const int N = 998244353;

const auto start_time = std::chrono::high_resolution_clock::now();

void zark() {
#ifdef ZARK
  auto end_time = std::chrono::high_resolution_clock::now();
  std::chrono::duration<double> diff = end_time - start_time;
  cerr << "Time Taken : " << diff.count() << "s\n";
#endif
}

#ifdef ZARK
#include "/home/aranjan/Desktop/CP/header.h"
#else
#define dbg(args...)
#endif

/* ------------------ Actual Coding Starts ------------------ */

bool ispow5(int n) {
  int x = pow(n, 0.2);
  return x * x * x * x * x == n;
}

void solve() {
  int x;
  cin >> x;
  fo(i, pow(x, 0.2)) {
    if (ispow5(x - i * i * i * i * i)) {
      cout << pow(x - i * i * i * i * i, 0.2) << " " << -i << endl;
      return;
    }
  }
  int i = 0;
  while (1) {
    if (ispow5(x + i * i * i * i * i)) {
      cout << pow(x + i * i * i * i * i, 0.2) << " " << i << endl;
      return;
    }
  }
}

int32_t main() {
  fastio;
#ifdef ZARK
  freopen("input.in", "r", stdin);
#endif

  // freopen("txt.in", "r", stdin);
  // freopen("txt.out", "w", stdout);
  // cout << fixed << setprecision(35);

  solve();
  zark();
  return 0;
}


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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long
#define endl "\n"

#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())      //
#define cpres(c, val) (find(all(c), val) != (c).end()) //

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

const int INF = 9e18;
// const int N = 1e9 + 7;
const int N = 998244353;

const auto start_time = std::chrono::high_resolution_clock::now();

void zark() {
#ifdef ZARK
  auto end_time = std::chrono::high_resolution_clock::now();
  std::chrono::duration<double> diff = end_time - start_time;
  cerr << "Time Taken : " << diff.count() << "s\n";
#endif
}

#ifdef ZARK
#include "/home/aranjan/Desktop/CP/header.h"
#else
#define dbg(args...)
#endif

/* ------------------ Actual Coding Starts ------------------ */

bool ispow5(int n) {
  int x = pow(n, 0.2);
  return x * x * x * x * x == n;
}

void solve() {
  int x;
  cin >> x;
  fo(i, pow(x, 0.2)) {
    if (ispow5(x - i * i * i * i * i)) {
      cout << pow(x - i * i * i * i * i, 0.2) << " " << -i << endl;
      return;
    }
  }
  for (int d = 1; d * d <= x; d++) {
    int k = x / d;
    for (int b = 0;
         pow((b + d), 4) + pow((b + d), 3) * b + (b + d) * (b + d) * b * b +
             (b + d) * b * b * b + b * b * b * b <=
         k;
         b++) {
      if (pow((b + d), 4) + pow((b + d), 3) * b + (b + d) * (b + d) * b * b +
              (b + d) * b * b * b + b * b * b * b ==
          k) {
        cout << b + d << " " << b << endl;
        return;
      }
    }
    for (int b = 0;
         pow((b + k), 4) + pow((b + k), 3) * b + (b + k) * (b + k) * b * b +
             (b + k) * b * b * b + b * b * b * b <=
         d;
         b++) {
      if (pow((b + k), 4) + pow((b + k), 3) * b + (b + k) * (b + k) * b * b +
              (b + k) * b * b * b + b * b * b * b ==
          k) {
        cout << b + k << " " << b << endl;
        return;
      }
    }
  }
}

int32_t main() {
  fastio;
#ifdef ZARK
  freopen("input.in", "r", stdin);
#endif

  // freopen("txt.in", "r", stdin);
  // freopen("txt.out", "w", stdout);
  // cout << fixed << setprecision(35);

  solve();
  zark();
  return 0;
}