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

#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (ll(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (ll(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    for (int WWW = 0; WWW < (n); WWW++)                                        \\
      cerr << v[WWW] << ' ';                                                   \\
    cerr << endl << endl;                                                      \\
  }
#define SHOW2d(v, i, j)                                                        \\
  {                                                                            \\
    for (int aaa = 0; aaa < i; aaa++) {                                        \\
      for (int bbb = 0; bbb < j; bbb++)                                        \\
        cerr << v[aaa][bbb] << ' ';                                            \\
      cerr << endl;                                                            \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

vector<ll> v;
bool seica[333333];

void f() {
  for (int i = 2; i < 333333; i++) {
    if (i % 7 == 1 || i % 7 == 6) {
      if (!seica[i]) {
        v.PB(i);
        for (int j = 2 * i; j < 333333; j += i) {
          seica[j] = true;
        }
      }
    }
  }
}

int main() {

  int n;
  f();
  while (cin >> n, n != 1) {
    cout << n << ':';

    REP(i, v.size()) {
      if (n % v[i] == 0) {
        printf(" %d", v[i]);
      }
      if (v[i] > n)
        break;
    }
    printf("\\n");
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (ll(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (ll(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    for (int WWW = 0; WWW < (n); WWW++)                                        \\
      cerr << v[WWW] << ' ';                                                   \\
    cerr << endl << endl;                                                      \\
  }
#define SHOW2d(v, i, j)                                                        \\
  {                                                                            \\
    for (int aaa = 0; aaa < i; aaa++) {                                        \\
      for (int bbb = 0; bbb < j; bbb++)                                        \\
        cerr << v[aaa][bbb] << ' ';                                            \\
      cerr << endl;                                                            \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

vector<ll> v;
bool seica[333333];

void f() {
  for (int i = 2; i < 333333; i++) {
    if (i % 7 == 1 || i % 7 == 6) {
      if (!seica[i]) {
        v.PB(i);
        for (int j = 2 * i; j < 333333; j += i) {
          seica[j] = true;
        }
      }
    }
  }
}

int main() {

  int n;
  f();
  while (cin >> n, n) {
    cout << n << ':';

    REP(i, v.size()) {
      if (n % v[i] == 0) {
        printf(" %d", v[i]);
      }
      if (v[i] > n)
        break;
    }
    printf("\\n");
  }
  return 0;
}