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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

const int PLUS[] = {-1, 1};

VI solve(int num) {
  vector<bool> isPrime(num + 1, true);
  VI res;

  for (int n = 1; 7 * n - 1 <= num; n++) {
    REP(i, 0, 2) {
      const int p = 7 * n + PLUS[i];

      if (!(num % p) && isPrime[p]) {
        res.PB(p);
        for (int j = 1; p * j <= num; j++) {
          isPrime[p * j] = false;
        }
      }
    }
  }

  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  for (int num; cin >> num, num != 1;) {
    VI res = solve(num);
    cout << num << ':';
    REP(i, 0, res.size()) { cout << ' ' << res[i]; }
    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

const int PLUS[] = {-1, 1};

VI solve(int num) {
  VI res;
  for (int n = 1; 1 < num; n++) {
    REP(i, 0, 2) {
      if (!(num % (7 * n + PLUS[i]))) {
        res.PB(7 * n + PLUS[i]);
        num /= (7 * n + PLUS[i]);
      }
    }

    while (res.size() && !(num % res.back())) {
      num /= res.back();
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  for (int num; cin >> num, num != 1;) {
    VI res = solve(num);
    cout << num << " :";
    REP(i, 0, res.size()) { cout << ' ' << res[i]; }
    cout << endl;
  }

  return 0;
}