alexjercan/bugnet huggingface dataset:
Problem p00734 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "algorithm"
#include "cmath"
#include "iomanip"
#include "iostream"
#include "map"
#include "set"
#include "string"
using namespace std;

#define TEST 0
#if TEST
FILE *in = freopen("./Q/question.txt", "r", stdin);
FILE *out = freopen("./A/answer.txt", "w", stdout);
#endif

int main() {
  int n, m;
  while (true) {
    int sa = 0, ans = 201, idxi = -1, idxj = -1;
    cin >> n >> m;
    set<int> tarous, hanakos;
    if (!n && !m)
      break;
    for (int i = 0; i < n + m; ++i) {
      int a;
      cin >> a;
      if (i < n) {
        tarous.insert(a);
        sa += a;
      } else {
        hanakos.insert(a);
        sa -= a;
      }
    }
    // cout <<sa<<endl;
    // cout <<tarousum <<" "<<hanakosum <<endl;
    if (!(sa & 1)) {
      bool FLAG = false;
      for (auto &&itr1 = tarous.begin(); itr1 != tarous.end(); ++itr1) {
        for (auto &&itr2 = hanakos.begin(); itr2 != hanakos.end(); ++itr2) {
          if (*itr1 - *itr2 == sa / 2) {
            if (ans > *itr1 + *itr2) {
              ans = *itr1 + *itr2;
              idxi = *itr1;
              idxj = *itr2;
              FLAG = true;
              break;
            }
          }
        }
        if (FLAG)
          break;
      }
    }
    if (ans == 201)
      cout << -1 << endl;
    else
      cout << idxi << " " << idxj << endl;
    tarous.clear();
    hanakos.clear();
  }
#if TEST
  fclose(in);
  fclose(out);
#endif
  return 0;
}

Error: TLE

Fixed submission:

#include "algorithm"
#include "cmath"
#include "iomanip"
#include "iostream"
#include "map"
#include "set"
#include "string"
using namespace std;

#define TEST 1
#if TEST
FILE *in = freopen("./Q/question.txt", "r", stdin);
FILE *out = freopen("./A/answer.txt", "w", stdout);
#endif

int main() {
  int n, m;
  while (true) {
    int sa = 0, ans = 201, idxi = -1, idxj = -1;
    cin >> n >> m;
    set<int> tarous, hanakos;
    if (!n && !m)
      break;
    for (int i = 0; i < n + m; ++i) {
      int a;
      cin >> a;
      if (i < n) {
        tarous.insert(a);
        sa += a;
      } else {
        hanakos.insert(a);
        sa -= a;
      }
    }
    // cout <<sa<<endl;
    // cout <<tarousum <<" "<<hanakosum <<endl;
    if (!(sa & 1)) {
      bool FLAG = false;
      for (auto &&itr1 = tarous.begin(); itr1 != tarous.end(); ++itr1) {
        for (auto &&itr2 = hanakos.begin(); itr2 != hanakos.end(); ++itr2) {
          if (*itr1 - *itr2 == sa / 2) {
            if (ans > *itr1 + *itr2) {
              ans = *itr1 + *itr2;
              idxi = *itr1;
              idxj = *itr2;
              FLAG = true;
              break;
            }
          }
        }
        if (FLAG)
          break;
      }
    }
    if (ans == 201)
      cout << -1 << endl;
    else
      cout << idxi << " " << idxj << endl;
    tarous.clear();
    hanakos.clear();
  }
#if TEST
  fclose(in);
  fclose(out);
#endif
  return 0;
}
Problem p00734 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int sum(int *, int);

int main(void) {

  int n, m, sub, flag, cnum1, cnum2, i, j, sum1, sum2;
  cin >> n >> m;
  int a[101], b[101];

  while ((n == 0 && m == 0) != 1) {

    //

    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (j = 0; j < m; j++) {
      cin >> b[j];
    }
    sub = sum(a, n) - sum(b, m);

    //

    flag = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if ((a[i] - b[j]) * 2 == sub) {
          if (flag == 0) {
            cnum1 = a[i];
            cnum2 = b[j];
            flag++;
          } else {
            if (a[i] + b[j] < cnum1 + cnum2) {
              cnum1 = a[i];
              cnum2 = b[j];
            }
          }
        }
      }
    }

    if (flag == 0) {
      cout << "-1" << endl;
    } else {
      cout << cnum1 << " " << cnum2 << endl;
    }

    cin >> n >> m;
  }

  return 0;
}

int sum(int *p, int n) {
  int s = 0, i;
  for (i = 0; i < n; i++)
    s += p[i];
  return s;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int sum(int *, int);

int main(void) {

  int n, m, sub, flag, cnum1, cnum2, i, j, sum1, sum2;
  cin >> n >> m;
  int a[n], b[m];

  while ((n == 0 && m == 0) != 1) {

    //

    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (j = 0; j < m; j++) {
      cin >> b[j];
      cout << sum(a, n);
    }
    cout << sum(a, n);
    sub = sum(a, n) - sum(b, m);

    //

    flag = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if ((a[i] - b[j]) * 2 == sub) {
          if (flag == 0) {
            cnum1 = a[i];
            cnum2 = b[j];
            flag++;
          } else {
            if (a[i] + b[j] < cnum1 + cnum2) {
              cnum1 = a[i];
              cnum2 = b[j];
            }
          }
        }
      }
    }

    if (flag == 0) {
      cout << "-1\\n";
    } else {
      cout << cnum1 << cnum2;
    }

    cin >> cnum1 >> cnum2;
  }

  return 0;
}

int sum(int *p, int n) {
  int s = 0, i;
  for (i = 0; i < n; i++)
    s += p[i];
  return s;
}
Problem p00734 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = (n)-1; i >= 0; i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define REPS(i, f, n) for (int i = (f)-1; i >= (n); i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

void slove(int n, int m) {
  vint vtaro(n);
  vint vhana(m);
  int sumtaro = 0, sumhana = 0;
  rep(i, n) {
    int tmp;
    scanf("%d", &tmp);
    sumtaro += tmp;
    vtaro[i] = tmp;
  }
  sort(all(vtaro));

  rep(i, m) {
    int tmp;
    scanf("%d", &tmp);
    sumhana += tmp;
    vhana[i] = tmp;
  }
  sort(all(vhana));

  double sa = sumtaro - sumhana; //????¨??????????
  rep(i, n) {
    rep(j, m) {
      if (vtaro[i] - vhana[j] == (sa / 2)) {
        printf("%d %d\\n", vtaro[i], vhana[j]);
        return;
      }
    }
  }
  printf("-1\\n");
  return;
}

int main(void) {
  int n, m;
  rep(i, 1000) {
    cin >> n >> m;

    if (n == 0)
      break;
    slove(n, m);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = (n)-1; i >= 0; i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define REPS(i, f, n) for (int i = (f)-1; i >= (n); i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

void slove(int n, int m) {
  vint vtaro(n);
  vint vhana(n);
  int sumtaro = 0, sumhana = 0;
  rep(i, n) {
    int tmp;
    scanf("%d", &tmp);
    sumtaro += tmp;
    vtaro[i] = tmp;
  }
  sort(all(vtaro));

  rep(i, m) {
    int tmp;
    scanf("%d", &tmp);
    sumhana += tmp;
    vhana[i] = tmp;
  }
  sort(all(vhana));

  double sa = sumtaro - sumhana; //????¨??????????
  rep(i, n) {
    rep(j, m) {
      if (vtaro[i] - vhana[j] == (sa / 2)) {
        printf("%d %d\\n", vtaro[i], vhana[j]);
        return;
      }
    }
  }
  printf("-1\\n");
  return;
}

int main(void) {
  int n, m;
  rep(i, 1000) {
    cin >> n >> m;

    if (n == 0)
      break;
    slove(n, m);
  }
  return 0;
}
Problem p00734 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m, sumN = 0, sumM = 0, ii = -1, jj = -1, flag = 0;
  int N[100], M[100];

  while (1) {
    cin >> n;
    cin >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; ++i) {
      cin >> N[i];
      sumN += N[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> M[i];
      sumM += M[i];
    }

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 0) {
          ii = i;
          jj = j;
          flag = 1;
        }
        if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 1 &&
            N[ii] + M[jj] > N[i] + M[j]) {
          ii = i;
          jj = j;
        }
      }
    }
    if (ii != -1 && jj != -1) {
      cout << N[ii] << " " << M[jj] << endl;
    } else
      cout << "-1" << endl;
    flag = 0;
    sumN = 0;
    sumM = 0;
    ii = -1;
    jj = -1;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, sumN = 0, sumM = 0, ii = -1, jj = -1, flag = 0;
  int N[100], M[100];

  while (1) {
    cin >> n;
    cin >> m;
    for (int i = 0; i < n; ++i) {
      cin >> N[i];
      sumN += N[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> M[i];
      sumM += M[i];
    }

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 0) {
          ii = i;
          jj = j;
          flag = 1;
        }
        if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 1 &&
            N[ii] + M[jj] > N[i] + M[j]) {
          ii = i;
          jj = j;
        }
      }
    }
    if (ii != -1 && jj != -1) {
      cout << N[ii] << " " << M[jj] << endl;
    } else
      cout << "-1" << endl;
    flag = 0;
    sumN = 0;
    sumM = 0;
    ii = -1;
    jj = -1;
  }
  return 0;
}
Problem p00734 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  while (1) {
    int t, h;
    cin >> t >> h;
    if (t == 0 && h == 0)
      break;
    vector<int> td;
    vector<int> hd;
    int tsum = 0;
    int hsum = 0;
    REP(i, t) {
      int tmp;
      cin >> tmp;
      td.pb(tmp);
      tsum += tmp;
    }
    REP(i, h) {
      int tmp;
      cin >> tmp;
      hd.pb(tmp);
      hsum += tmp;
    }
    int ansx = 114514;
    int ansy = 114514;
    REP(i, t) {
      REP(j, h) {
        if (tsum - td[i] + hd[j] == hsum - hd[j] + td[i]) {
          if ((ansx + ansy) > (i + j)) {
            ansx = i;
            ansy = j;
            i = t;
            j = h;
          }
        }
      }
    }
    if (ansx == 114514)
      cout << -1 << endl;
    else
      cout << td[ansx] << " " << hd[ansy] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  while (1) {
    int t, h;
    cin >> t >> h;
    vector<int> td;
    vector<int> hd;
    int tsum = 0;
    int hsum = 0;
    REP(i, t) {
      int tmp;
      cin >> tmp;
      td.pb(tmp);
      tsum += tmp;
    }
    REP(i, h) {
      int tmp;
      cin >> tmp;
      hd.pb(tmp);
      hsum += tmp;
    }
    int ansx = 114514;
    int ansy = 114514;
    REP(i, t) {
      REP(j, h) {
        if (tsum - td[i] + hd[j] == hsum - hd[j] + td[i]) {
          if ((ansx + ansy) > (i + j)) {
            ansx = i;
            ansy = j;
            i = t;
            j = h;
          }
        }
      }
    }
    if (ansx == 114514)
      cout << -1 << endl;
    else
      cout << td[ansx] << " " << hd[ansy] << endl;
  }
}
Problem p00734 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair<int, int> iP;
typedef pair<iP, int> iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

  int n, m;
  while (cin >> n >> m, n) {
    int sumt = 0, sumh = 0;
    vector<int> ts(n), hs(m);
    for (int i = 0; i < n; i++) {
      cin >> ts[i];
      sumt += ts[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> hs[i];
      sumh += hs[i];
    }
    int mint = INF, minh = INF;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (sumt - ts[i] + hs[j] == sumh - hs[j] + ts[i] &&
            mint + minh > ts[i] + hs[j])
          mint = ts[i], minh = hs[j];
      }
    }
    if (mint == INF)
      cout << -1 << endl;
    else
      cout << mint << " " << minh << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair<int, int> iP;
typedef pair<iP, int> iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

  int n, m;
  while (cin >> n >> m, n) {
    int sumt = 0, sumh = 0;
    vector<int> ts(n), hs(n);
    for (int i = 0; i < n; i++) {
      cin >> ts[i];
      sumt += ts[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> hs[i];
      sumh += hs[i];
    }
    int mint = INF, minh = INF;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (sumt - ts[i] + hs[j] == sumh - hs[j] + ts[i] &&
            mint + minh > ts[i] + hs[j])
          mint = ts[i], minh = hs[j];
      }
    }
    if (mint == INF)
      cout << -1 << endl;
    else
      cout << mint << " " << minh << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define MAX_N 300000

using namespace std;

int N;
int p[MAX_N + 1], ans[MAX_N + 1];

int main() {
  for (int i = 0; i < MAX_N; i++) {
    if (i % 7 != 1 && i % 7 != 6)
      p[i] = 0;
    else
      p[i] = i;
  }
  p[1] = 0;
  for (int i = 6; i < MAX_N;) {
    for (int j = i * 2; j < MAX_N; j += i) {
      p[j] = 0;
    }
    int k = i + 1;
    while (p[k] == 0) {
      k++;
      if (k >= MAX_N)
        break;
    }
    i = k;
  }
  while (1) {
    cin >> N;
    if (N == 1)
      break;
    int count = 0;
    for (int i = 2; i <= N; i++) {
      if (N % i == 0 && p[i] != 0) {
        ans[count] = i;
        count++;
      }
    }
    cout << N << ": ";
    for (int i = 0; i < count - 1; i++) {
      cout << ans[i] << " ";
    }
    cout << ans[count - 1] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

#define MAX_N 300000

using namespace std;

int N;
int p[MAX_N + 1], ans[MAX_N + 1];

int main() {
  for (int i = 0; i < MAX_N; i++) {
    if (i % 7 != 1 && i % 7 != 6)
      p[i] = 0;
    else
      p[i] = i;
  }
  p[1] = 0;
  for (int i = 6; i < MAX_N;) {
    for (int j = i * 2; j < MAX_N; j += i) {
      p[j] = 0;
    }
    int k = i + 1;
    while (p[k] == 0)
      k++;
    i = k;
  }
  while (1) {
    cin >> N;
    if (N == 1)
      break;
    int count = 0;
    for (int i = 2; i <= N; i++) {
      if (N % i == 0 && p[i] != 0) {
        ans[count] = i;
        count++;
      }
    }
    cout << N << ": ";
    for (int i = 0; i < count - 1; i++) {
      cout << ans[i] << " ";
    }
    cout << ans[count - 1] << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

bool a[500001];

int main() {
  vector<int> p;
  p.push_back(6);
  for (int i = 1; i <= 50000; i++) {
    a[6 * i] = 1;
  }
  for (int i = 1; 7 * i + 1 <= 300000; i++) {
    if (a[7 * i + 1] == 0) {
      p.push_back(7 * i + 1);
      for (int j = 7 * i + 1; j <= 300000; j += 7 * i + 1) {
        a[j] = 1;
      }
    }
    if (a[7 * i + 6] == 0) {
      p.push_back(7 * i + 6);
      for (int j = 7 * i + 6; j <= 300000; j += 7 * i + 6) {
        a[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n && n != 1) {
    vector<int> v;
    for (int i = 0; i < p.size(); i++) {
      if (n % p[i] == 0) {
        v.push_back(p[i]);
      }
    }
    cout << n << ":";
    for (int i = 0; i < v.size(); i++) {
      cout << " " << v[i];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

bool a[300001];

int main() {
  vector<int> p;
  p.push_back(6);
  for (int i = 1; i <= 50000; i++) {
    a[6 * i] = 1;
  }
  for (int i = 1; 7 * i + 1 <= 300000; i++) {
    if (a[7 * i + 1] == 0) {
      p.push_back(7 * i + 1);
      for (int j = 7 * i + 1; j <= 300000; j += 7 * i + 1) {
        a[j] = 1;
      }
    }
    if (a[7 * i + 6] == 0) {
      p.push_back(7 * i + 6);
      for (int j = 7 * i + 6; j <= 300000; j += 7 * i + 6) {
        a[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n && n != 1) {
    vector<int> v;
    for (int i = 0; i < p.size(); i++) {
      if (n % p[i] == 0) {
        v.push_back(p[i]);
      }
    }
    cout << n << ":";
    for (int i = 0; i < v.size(); i++) {
      cout << " " << v[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef vector<vector<int>> vector2d;

int main() {

  int i, j, n;
  vector<int> prime;

  int judge[300000] = {};

  for (i = 0; i < 42857; i++) {
    judge[i * 7 + 1] = 1;
    judge[i * 7 + 6] = 1;
  }
  judge[1] = 0;

  // 素数リスト作成
  for (i = 6; i < 300000; i++) {
    if (judge[i] == 1) {
      prime.push_back(i);
      // cout << i <<endl;
      for (j = 2; j * i < 300000; j++) {
        judge[j * i] = 0;
      }
    }
  }
  prime.push_back(300100);

  while (1) {
    cin >> n;
    if (n == 1)
      break;

    string ans;
    cout << n << ":";

    for (i = 0; prime[i] <= n; i++) {
      if (n % prime[i] == 0) {
        cout << " " << prime[i];
      }
    }

    cout << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef vector<vector<int>> vector2d;

string IntToString(int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}

int main() {

  int i, j, n;
  vector<int> prime;

  int judge[300000] = {};

  for (i = 1; i < 42857; i++) {
    judge[i * 7 + 1] = 1;
    judge[i * 7 + 6] = 1;
  }

  // 素数リスト作成
  for (i = 8; i < 300000; i++) {
    if (judge[i] == 1) {
      prime.push_back(i);
      for (j = 2; j < 300000 / i; j++) {
        judge[j * i] = 0;
      }
    }
  }

  while (1) {
    cin >> n;
    if (n == 1)
      break;

    cout << "bb" << endl;

    string ans;
    ans = IntToString(n) + ":";

    // cout << ans <<endl;

    for (i = 0; n != 1; i++) {
      if (n % prime[i] == 0) {
        ans += " " + IntToString(prime[i]);
        n = n / prime[i];
      }
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MAX = 300005;
bool isPrime[MAX];
vector<int> mt;
void makePrime() {
  for (int i = 6; i < MAX; i++) {
    isPrime[i] = true;
  }
  for (int i = 2; i < MAX; i++) {
    if (isPrime[i] && (i % 7 == 6 || i % 7 == 1)) {
      mt.push_back(i);
      for (int j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  return;
}
int main() {
  int n;
  makePrime();
  int len = mt.size();
  while (cin >> n, n != 1) {
    set<int> SET;
    for (int i = 0; i < len; i++) {
      if (n % mt[i] == 0) {
        SET.insert(mt[i]);
      }
    }
    cout << n << ":";
    for (auto s : SET) {
      cout << " " << s;
    }
    cout << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MAX = 300005;
bool isPrime[MAX];
vector<int> mt;
void makePrime() {
  for (int i = 6; i < MAX; i++) {
    isPrime[i] = true;
  }
  for (int i = 2; i < MAX; i++) {
    if (isPrime[i] && (i % 7 == 6 || i % 7 == 1)) {
      mt.push_back(i);
      for (int j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  return;
}
int main() {
  int n;
  makePrime();
  int len = mt.size();
  while (cin >> n, n) {
    set<int> SET;
    for (int i = 0; i < len; i++) {
      if (n % mt[i] == 0) {
        SET.insert(mt[i]);
      }
    }
    cout << n << ":";
    for (auto s : SET) {
      cout << " " << s;
    }
    cout << '\\n';
  }
  return 0;
}