Problem p02963 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const double EPS = 1e-9;
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
inline ll powint(ll x, ll y) {
  ll r = 1;
  while (y) {
    if (y & 1)
      r *= x;
    x *= x;
    y >>= 1;
  }
  return r;
}
inline ll powmod(ll x, ll y, ll m = MOD) {
  ll r = 1;
  while (y) {
    if (y & 1)
      r *= x;
    x *= x;
    r %= m;
    x %= m;
    y >>= 1;
  }
  return r;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// http://orolog.hatenablog.jp/entry/20100804/1280943541
// a * b % mを返す．
ll multMod(ll a, ll b, ll m) {
  ll res = 0;
  a %= m;
  while (b) {
    if (b & 1) {
      res = (res + a) % m;
    }
    a = (a * 2) % m;
    b = b / 2;
  }
  return res;
}

// cははじめ1を入れる．
// numが素数の場合無限ループしてしまう．判定もするなら適度なcで打ち切る．*/
ll PollardRho(ll num, ll c) {
  if (c > 1000)
    return -1;
  ll x, y, p;
  x = y = p = 1LL;
  while (p == 1) {
    x = (multMod(x, x, num) + c) % num;
    ll ty = (multMod(y, y, num) + c) % num;
    y = (multMod(ty, ty, num) + c) % num;
    if (x == y)
      return PollardRho(num, c + 1);
    p = GCD(num, llabs(x - y));
  }
  return p;
}

// https://ei1333.github.io/luzhiled/snippets/math/divisor.html
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = sqrt(n) + 1; i >= 1; i--) {
    if (n % i == 0) {
      ret.push_back(i);
      return (ret);
    }
  }
  return (ret);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll s;
  cin >> s;
  /*
  ll div = PollardRho(s,1);
  dump(div);
  if(div == -1){
      cout << "0 0 0 " << s << " 1 0" << endl;
      return 0;
  }else{
      vll divs;
      divs = divisor(s);
      cout << "0 0 0 " << divs[0] << " " << s/divs[0] << " 0" << endl;
      return 0;
  }
  */
  if (s <= (ll)1e9) {
    cout << "0 0 0 " << s << " 1 0" << endl;
    return 0;
  }
  ll cl = 1;
  for (ll i = sqrt(s) + EPS; i <= (ll)1e9; i++)
    for (ll j = sqrt(s) + EPS, c = 0; j <= (ll)1e9 && c <= cl; j++, c++) {
      if (i * j == s) {
        cout << "0 0 ";
        cout << i;
        cout << " ";
        cout << 0;
        cout << " ";
        cout << 0;
        cout << " ";
        cout << j;
        cout << endl;
        return 0;
      }
      ll x = i * j - s;
      ll div = PollardRho(x, 1);
      if (div != -1) {
        vll divs;
        divs = divisor(x);
        if (divs.empty())
          continue;
        cout << "0 0 ";
        cout << i;
        cout << " ";
        cout << divs[0];
        cout << " ";
        cout << x / divs[0];
        cout << " ";
        cout << j;
        cout << endl;
        return 0;
      }
      cl++;
    }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const double EPS = 1e-9;
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
inline ll powint(ll x, ll y) {
  ll r = 1;
  while (y) {
    if (y & 1)
      r *= x;
    x *= x;
    y >>= 1;
  }
  return r;
}
inline ll powmod(ll x, ll y, ll m = MOD) {
  ll r = 1;
  while (y) {
    if (y & 1)
      r *= x;
    x *= x;
    r %= m;
    x %= m;
    y >>= 1;
  }
  return r;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// http://orolog.hatenablog.jp/entry/20100804/1280943541
// a * b % mを返す．
ll multMod(ll a, ll b, ll m) {
  ll res = 0;
  a %= m;
  while (b) {
    if (b & 1) {
      res = (res + a) % m;
    }
    a = (a * 2) % m;
    b = b / 2;
  }
  return res;
}

// cははじめ1を入れる．
// numが素数の場合無限ループしてしまう．判定もするなら適度なcで打ち切る．*/
ll PollardRho(ll num, ll c) {
  if (c > 1000)
    return -1;
  ll x, y, p;
  x = y = p = 1LL;
  while (p == 1) {
    x = (multMod(x, x, num) + c) % num;
    ll ty = (multMod(y, y, num) + c) % num;
    y = (multMod(ty, ty, num) + c) % num;
    if (x == y)
      return PollardRho(num, c + 1);
    p = GCD(num, llabs(x - y));
  }
  return p;
}

// https://ei1333.github.io/luzhiled/snippets/math/divisor.html
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = sqrt(n) + 1; i >= 1; i--) {
    if (n % i == 0) {
      ret.push_back(i);
      return (ret);
    }
  }
  return (ret);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll s;
  cin >> s;
  /*
  ll div = PollardRho(s,1);
  dump(div);
  if(div == -1){
      cout << "0 0 0 " << s << " 1 0" << endl;
      return 0;
  }else{
      vll divs;
      divs = divisor(s);
      cout << "0 0 0 " << divs[0] << " " << s/divs[0] << " 0" << endl;
      return 0;
  }
  */
  if (s <= (ll)1e9) {
    cout << "0 0 0 " << s << " 1 0" << endl;
    return 0;
  }
  ll cl = 1;
  for (ll i = sqrt(s) + EPS; i <= (ll)1e9; i++)
    for (ll j = sqrt(s) + EPS, c = 0; j <= (ll)1e9 && c <= cl; j++, c++) {
      if (i * j == s) {
        cout << "0 0 ";
        cout << i;
        cout << " ";
        cout << 0;
        cout << " ";
        cout << 0;
        cout << " ";
        cout << j;
        cout << endl;
        return 0;
      }
      ll x = i * j - s;
      if (x < 0)
        continue;
      dump(i, j, x);
      if (x <= (ll)1e9) {
        cout << "0 0 ";
        cout << i;
        cout << " ";
        cout << x;
        cout << " ";
        cout << 1;
        cout << " ";
        cout << j;
        cout << endl;
        return 0;
      }
      ll div = PollardRho(x, 1);
      if (div != -1) {
        vll divs;
        divs = divisor(x);
        if (divs.empty())
          continue;
        cout << "0 0 ";
        cout << i;
        cout << " ";
        cout << divs[0];
        cout << " ";
        cout << x / divs[0];
        cout << " ";
        cout << j;
        cout << endl;
        return 0;
      }
      cl++;
    }
  return 0;
}