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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long i64;

// bool isPrime(int num){
//     for(int i=6;i<num;i=(i%7==1 ? i+5:i+2)){
//         if(num%i==0) return false;
//     }
//     return true;
// }

int main() {
  int flags[300000 + 1];
  rep(i, 300001) flags[i] = true;
  for (int i = 6; i <= 300000; i = (i % 7 == 1 ? i + 5 : i + 2)) {
    if (flags[i]) {
      for (int j = i * 2; j <= 300000; j += i) {
        flags[j] = false;
      }
    }
  }
  while (true) {
    int num;
    cin >> num;
    if (num == 1)
      break;

    vector<int> ans;
    for (int i = 6; i <= num; i = (i % 7 == 1 ? i + 5 : i + 2)) {
      if (num % i == 0 && flags[i]) {
        ans.push_back(i);
      } // else if(num%i==0 && isPrime(num/i)){
      //     ans.insert(num/i);
      // }
    }
    cout << num << ": ";
    // for(set<int>::iterator itr=ans.begin();itr!=ans.end();itr++){
    //     cout << *itr << " ";
    // }
    rep(i, ans.size()) {
      cout << ans[i];
      if (i != ans.size() - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long i64;

bool isPrime(int num) {
  for (int i = 6; i < num; i = (i % 7 == 1 ? i + 5 : i + 2)) {
    if (num % i == 0)
      return false;
  }
  return true;
}
int main() {
  while (true) {
    int num;
    cin >> num;
    if (num == 1)
      break;
    set<int> ans;
    if (isPrime(num)) {
      cout << num << endl;
      continue;
    }
    for (int i = 6; i <= num / 2; i = (i % 7 == 1 ? i + 5 : i + 2)) {
      if (isPrime(i) && num % i == 0) {
        ans.insert(i);
      }
    }
    for (set<int>::iterator itr = ans.begin(); itr != ans.end(); itr++) {
      cout << *itr << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define MAX 3000000
using namespace std;
int msNum[MAX];
int prime[MAX];
bool is_prime[MAX + 1];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[msNum[i]] = true;
  is_prime[msNum[0]] = is_prime[msNum[1]] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[msNum[i]] == true) {
      prime[p++] = msNum[i];
      // cout<<msNum[i]<<endl;
      for (int j = 2 * msNum[i]; j <= n; j += msNum[i])
        is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int n, p, i = 0;
  while (msNum[2 * i] < MAX) {
    msNum[2 * i + 1] = 7 * i + 1;
    msNum[2 * i + 2] = 7 * i + 6;
    i++;
  }
  while (cin >> n) {
    if (n == 1)
      break;
    p = sieve(n);
    cout << n << ":";
    for (int i = 0; i < p; i++) {
      if (n % prime[i] == 0) {
        while (n % prime[i] != 0)
          n %= prime[i];
        cout << " " << prime[i];
      }
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#define MAX 3000000
using namespace std;
int msNum[MAX];
int prime[MAX];
bool is_prime[MAX + 1];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[msNum[i]] = true;
  is_prime[msNum[0]] = is_prime[msNum[1]] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[msNum[i]] == true) {
      prime[p++] = msNum[i];
      // cout<<msNum[i]<<endl;
      for (int j = 2 * msNum[i]; j <= n; j += msNum[i])
        is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int n, p;
  for (int i = 0; i < MAX - 2; i++) {
    msNum[2 * i + 1] = 7 * i + 1;
    msNum[2 * i + 2] = 7 * i + 6;
  }
  while (cin >> n) {
    if (n == 1)
      break;
    p = sieve(n);
    cout << n << ": ";
    for (int i = 0; i < p; i++) {
      if (n % prime[i] == 0) {
        while (n % prime[i] != 0)
          n %= prime[i];
        cout << prime[i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

// 15
#include <iostream>
#include <vector>

#define MS(X) ((X / 2) * 7 + ((X % 2) ? 6 : 1))

using namespace std;

int main() {
  bool mcmp[300000] = {};
  vector<int> mspf;
  for (int i = 1; MS(i) < 300000; i++) {
    if (!mcmp[MS(i)]) {
      mspf.push_back(MS(i));
      for (int j = 1; MS(i) * MS(j) < 300000; j++) {
        mcmp[MS(i) * MS(j)] = true;
      }
    }
  }
  for (int n; cin >> n, n != 1;) {
    cout << n << ':';
    for (int i = 0; i < mspf.size(); i++) {
      if (n % mspf[i] == 0) {
        cout << ' ' << mspf[i];
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// 15
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> msnv;
  for (int i = 0; i * 7 < 300000; i++) {
    msnv.push_back(i * 7 + 1);
    msnv.push_back(i * 7 + 6);
  }
  msnv.erase(msnv.begin());
  vector<int> msnpf(msnv.size());
  vector<int> mspf;
  for (int i = 0; i < msnv.size(); i++) {
    if (!msnpf[i]) {
      mspf.push_back(msnv[i]);
      for (int j = i + 1; j < msnv.size(); j++) {
        if (msnv[j] % msnv[i] == 0) {
          msnpf[j] = 1;
        }
      }
    }
  }
  for (int n; cin >> n, n != 1;) {
    cout << n << ':';
    for (int i = 0; i < mspf.size(); i++) {
      if (n % mspf[i] == 0) {
        cout << ' ' << mspf[i];
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
  vector<ll> d;
  vector<bool> p(300000);
  p[0] = p[1] = true;

  for (ll i = 2; i < 300000; ++i) {
    if ((i % 7 == 1 || i % 7 == 6) && !p[i]) {
      d.pb(i);
      for (ll j = 1; i * j < 300000; ++j) {
        p[i * j] = true;
      }
    }
  }
  while (true) {
    ll n;
    cin >> n;
    if (n == 1)
      break;
    cout << n << ":";
    REP(i, d.size()) {
      if (d[i] > n)
        break;
      if (n % d[i] == 0) {
        cout << " " << d[i];
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
  vector<ll> d;
  for (ll i = 2; i < 300000; ++i) {
    if (i % 7 == 1 || i % 7 == 6) {
      bool f = false;
      REP(j, d.size()) {
        if (i % d[j] == 0) {
          f = true;
          break;
        }
      }
      if (!f)
        d.pb(i);
    }
  }
  while (true) {
    ll n;
    cin >> n;
    if (n == 1)
      break;
    cout << n << ":";
    REP(i, d.size()) {
      if (d[i] > n)
        break;
      if (n % d[i] == 0) {
        cout << " " << d[i];
      }
    }
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<int> divisors(int n) {
  vector<int> div2;

  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i % 7 == 1 || i % 7 == 6) {
        div2.push_back(i);
      }

      if (((n / i) % 7 == 1 || (n / i) % 7 == 6) && i * i != n) {
        div2.push_back(n / i);
      }
    }
  }

  sort(div2.begin(), div2.end());

  return div2;
}

vector<int> divisorsdiv2(int n) {
  vector<int> divisor = divisors(n);

  vector<int> div2;

  for (int i = 0; i < divisor.size(); i++) {
    if (divisors(divisor[i]).size() == 2 && divisor[i] != 1) {
      div2.push_back(divisor[i]);
    }
  }

  return div2;
}

int main() {
  int n;

  while (true) {
    cin >> n;

    if (n == 1) {
      break;
    }

    vector<int> div2 = divisorsdiv2(n);

    cout << n << ':';

    for (int i = 0; i < div2.size(); i++) {
      cout << ' ' << div2[i];
    }

    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

bool MS_Number(int n) { return n % 7 == 1 || n % 7 == 6; }

bool is_MS_prime(int n, int k = 6) {
  if (k * k > n) {
    return true;
  }

  if (n % k == 0) {
    return false;
  }

  if (k % 7 == 1) {
    return is_MS_prime(n, k + 5);
  }
  if (k % 7 == 6) {
    return is_MS_prime(n, k + 2);
  }
}

int main() {
  int n;

  while (true) {
    cin >> n;

    if (n == 1) {
      break;
    }

    cout << n << ":";

    for (int i = 2; i <= n; i++) {
      if (MS_Number(i) == true) {
        if (is_MS_prime(i) == true && n % i == 0) {
          cout << ' ' << i;
        }
      }
    }

    cout << endl;
  }

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

#include <iostream>
#include <vector>
using namespace std;

#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)

int main() {
  while (true) {
    vector<int> temp;

    rep(i, 0, 300001) { temp.push_back(i); }

    int n;
    cin >> n;
    if (n == 1) {
      break;
    }

    cout << n << ":";

    rep(i, 6, 300001) {
      if (temp[i] % 7 == 1 || temp[i] % 7 == 6) {
        if (temp[i] != 0) {
          if (n % temp[i] == 0) {
            cout << " " << temp[i];
          }
          for (int j = i + i; j <= n; j += i) {
            temp[j] = 0;
          }
        }
      }
    }
    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 1) {
      break;
    }

    cout << n << ":";

    rep(i, 2, n + 1) {
      if (i % 7 == 1 || i % 7 == 6) {
        bool isprime = true;
        rep(j, 2, i) {
          if (j % 7 == 1 || j % 7 == 6) {
            if (i % j == 0) {
              isprime = false;
              break;
            }
          }
        }
        if (isprime == true) {
          if (n % i == 0) {
            cout << " " << i;
          }
        }
      }
    }

    cout << endl;
  }

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

#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> vi;
  int n;
  vector<bool> prime(300001, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i <= 300000; i++) {
    if (!prime[i])
      continue;
    if (((i % 7) != 1) && ((i % 7) != 6)) {
      prime[i] = false;
      continue;
    }

    for (int k = 2 * i; k <= 300000; k += i)
      prime[k] = false;
  }

  while (cin >> n && (n != 1)) {
    cout << n << ":";
    for (int i = 2; i <= n; i++) {
      if (prime[i] && (n % i) == 0)
        cout << " " << i;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> vi;
  int n;
  while (cin >> n && (n != 1))
    vi.push_back(n);

  for (int i = 0; i < vi.size(); i++) {
    int val = vi[i];

    cout << val << ":";
    for (int x = 2; x <= val; x++) {
      int mod_x = x % 7;
      if (mod_x == 1 || mod_x == 6) {
        bool flag = true;
        for (int y = 2; y * y <= x; y++) {
          int mod_y = y % 7;
          if (mod_y == 1 || mod_y == 6) {
            if (x % y == 0) {
              flag = false;
              break;
            }
          }
        }
        if (flag && (val % x) == 0)
          cout << " " << x;
      }
    }
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <time.h>
using namespace std;

//?????????????´???°??¨????????°
int prime[100000];
int primeNum;
bool flag;

//??\\??????
int N;

int main() {
  //?????????????´???°?????????
  // clock_t start=clock();
  primeNum = 0;
  for (int i = 7; i < 300000; i += 7) {
    flag = true;
    //??¢??\\????´???°??§??????????????????????´???°????????????
    for (int j = 0; j < primeNum; j++) {
      if ((i - 1) < prime[j] * prime[j])
        break;
      if ((i - 1) % prime[j] == 0)
        flag = false;
    }
    if (flag)
      prime[primeNum++] = i - 1;

    flag = true;
    for (int j = 0; j < primeNum; j++) {
      if ((i + 1) < prime[j] * prime[j])
        break;
      if ((i + 1) % prime[j] == 0)
        flag = false;
    }
    if (flag)
      prime[primeNum++] = i + 1;
  }

  // clock_t end = clock();

  // cout<<(double)(end-start)<<endl;

  //??\\?????¨??????
  while (true) {
    cin >> N;
    if (N == 1)
      break;
    cout << N << ":";
    for (int i = 0; i < primeNum; i++) {
      if (N % prime[i] == 0)
        cout << " " << prime[i];
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

//?????????????´???°??¨????????°
int prime[100000];
int primeNum;
bool flag;

//??\\??????
int N;

int main() {
  //?????????????´???°?????????
  primeNum = 0;
  for (int i = 7; i < 300000; i += 7) {
    flag = true;
    //??¢??\\????´???°??§??????????????????????´???°????????????
    for (int j = 0; j < primeNum; j++) {
      if ((i - 1) % prime[j] == 0)
        flag = false;
    }
    if (flag)
      prime[primeNum++] = i - 1;

    flag = true;
    for (int j = 0; j < primeNum; j++) {
      if ((i + 1) % prime[j] == 0)
        flag = false;
    }
    if (flag)
      prime[primeNum++] = i + 1;
  }

  //??\\?????¨??????
  while (true) {
    cin >> N;
    if (N == 1)
      break;
    cout << N << ":";
    for (int i = 0; i < primeNum; i++) {
      if (N % prime[i] == 0)
        cout << " " << prime[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, i, j, k, f;
  vector<int> sm;
  for (i = 1; i < 60000 / 7 + 1; i++) {
    f = 0;
    for (j = 0; j < sm.size(); j++) {
      if ((7 * i - 1) % sm[j] == 0)
        f = 1;
    }
    if (f == 0)
      sm.push_back(7 * i - 1);
    f = 0;
    for (j = 0; j < sm.size(); j++) {
      if ((7 * i + 1) % sm[j] == 0)
        f = 1;
    }
    if (f == 0)
      sm.push_back(7 * i + 1);
  }
  cin >> n;
  while (n != 1) {
    cout << n << ":";
    f = 0;
    for (i = 0; i < sm.size(); i++) {
      if (n % sm[i] == 0) {
        cout << " " << sm[i];
        f = 1;
      }
    }
    if (f == 0)
      cout << " " << n;
    cout << endl;
    cin >> n;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, i, j, k, f;
  vector<int> sm;
  for (i = 1; i < 300000 / 7 + 1; i++) {
    f = 0;
    for (j = 0; j < sm.size(); j++) {
      if ((7 * i - 1) % sm[j] == 0)
        f = 1;
    }
    if (f == 0)
      sm.push_back(7 * i - 1);
    f = 0;
    for (j = 0; j < sm.size(); j++) {
      if ((7 * i + 1) % sm[j] == 0)
        f = 1;
    }
    if (f == 0)
      sm.push_back(7 * i + 1);
  }
  cin >> n;
  while (n != 1) {
    cout << n << ":";
    for (i = 0; i < sm.size(); i++) {
      if (n % sm[i] == 0)
        cout << " " << sm[i];
    }
    cout << endl;
    cin >> n;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  vector<int> primes;
  for (int i = 7; i <= 300001; i += 7) {
    rep(j, 2) {
      int a = i + 2 * j - 1;
      bool f = true;
      bool bf = true;
      for (int k = 7; bf && f; k += 7) {
        rep(l, 2) {
          int b = k + 2 * l - 1;
          if ((b * b) > a) {
            bf = false;
            break;
          }
          f &= a % b != 0;
        }
      }

      if (f) {
        primes.push_back(a);
      }
    }
  }
  while (cin >> n, n != 1) {
    cout << n << ":";
    for (auto v : primes) {
      if (n % v == 0) {
        cout << " " << v;
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  while (cin >> n, n != 1) {
    cout << n << ":";
    for (int i = 7; i <= 300001; i += 7) {
      rep(j, 2) {
        int a = i + 2 * j - 1;
        bool f = true;
        bool bf = true;
        for (int k = 7; bf; k += 7) {
          rep(l, 2) {
            int b = k + 2 * l - 1;
            if ((b * b) > a) {
              bf = false;
              break;
            }
            f &= a % b != 0;
          }
        }

        if (f && n % a == 0) {
          cout << " " << a;
        }
      }
    }
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
  int a[200000], c = 0, n;
  r(i, 3, 300000) if (i % 7 == 1 || i % 7 == 6) {
    int p = 1;
    if (i > 10 && (i % 6 == 0 || i % 8 == 0))
      continue;
    r(k, 0, c) if (i % a[k] == 0) p = 0;
    if (p)
      a[c++] = i;
  }
  while (cin >> n, n != 1) {
    int s = 0;
    cout << n << ':';
    r(i, 0, c) if (n % a[i] == 0) cout << ' ' << a[i];
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
  int a[200000], c = 0, n;
  r(i, 3, 300000) if (i % 7 == 1 || i % 7 == 6) {
    int p = 1;
    if (i > 10 && (i % 6 == 0 || i % 8 == 0))
      continue;
    r(k, 0, c) if (i % a[k] == 0) p = 0;
    if (p)
      a[c++] = i;
  }
  r(i, 0, c) cout << a[i] << endl;
  while (cin >> n, n != 1) {
    int s = 0;
    cout << n << ':';
    r(i, 0, c) if (n % a[i] == 0) cout << ' ' << a[i];
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <fstream>
#include <iostream>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1154&lang=jp

using namespace std;

ifstream fin;
ofstream fout;

int main() {

  fin.open("input.ans");
  fout.open("output.txt");

  int n;           // input
  int a[2];        // 月曜土曜素因数
  int b[300] = {}; // 因数記憶
  int j = 0;
  bool isPrime = true;

  while (true) {
    cin >> n;

    // 初期化
    a[0] = 6;
    a[1] = 8;
    b[0] = 3;
    j = 0;

    if (n == 1)
      break;

    cout << n << ':';
    // fout << n << ':';

    while (a[0] <= n / 6) {
      for (int k = 0; k < 2; k++) {

        isPrime = true;

        if (n % a[k] == 0) {
          for (int m = 0; m < j; m++)
            if (a[k] % b[m] == 0)
              isPrime = false;
          if (isPrime == true) {
            cout << ' ' << a[k];
            //	fout << ' ' << a[k];
            b[j] = a[k];
            //					//	cout << " b[" << j << "]= " << b[j] <<
            //endl;
            j++;
          }
        }
        a[k] += 7;
        //				for (int m = 0; m < j; m++)
        //					if (a[k] % b[m] == 0)a[k] += 7;
      }
    }

    if (b[0] == 3) {
      cout << ' ' << n;
      //	fout << ' ' << n;
    }
    cout << endl;
    // fout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iostream>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1154&lang=jp

using namespace std;

ifstream fin;
ofstream fout;

int main() {

  fin.open("A.ans");
  fout.open("output.txt");

  int n;           // input
  int a[2];        // 月曜土曜素因数
  int b[300] = {}; // 因数記憶
  int j = 0;
  bool isPrime = true;

  while (true) {
    fin >> n;

    // 初期化
    a[0] = 6;
    a[1] = 8;
    b[0] = 3;
    j = 0;

    if (n == 1)
      break;

    cout << n << ':';
    // fout << n << ':';

    while (a[0] <= n / 6) {
      for (int k = 0; k < 2; k++) {

        isPrime = true;

        if (n % a[k] == 0) {
          for (int m = 0; m < j; m++)
            if (a[k] % b[m] == 0)
              isPrime = false;
          if (isPrime == true) {
            cout << ' ' << a[k];
            //	fout << ' ' << a[k];
            b[j] = a[k];
            //					//	cout << " b[" << j << "]= " << b[j] <<
            //endl;
            j++;
          }
        }
        a[k] += 7;
        //				for (int m = 0; m < j; m++)
        //					if (a[k] % b[m] == 0)a[k] += 7;
      }
    }

    if (b[0] == 3) {
      cout << ' ' << n;
      //	fout << ' ' << n;
    }
    cout << endl;
    // fout << endl;
  }

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

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int n;
  int a[42858][2] = {0};
  a[1][0] = 1;
  a[1][1] = 1;
  for (int i = 2; i <= 42857; i++) {
    if (a[i][0] == 2)
      goto end1;
    for (int j = 1; j < i / 2 + 1; j++) {
      if (a[j][0] == 1) {
        if ((7 * i - 1) % (7 * j - 1) == 0) {
          a[i][0] = 2;
          goto end1;
        }
      }
      if (a[j][1] == 1) {
        if ((7 * i - 1) % (7 * j + 1) == 0) {
          a[i][0] = 2;
          goto end1;
        }
      }
    }
    a[i][0] = 1;
    for (int j = 1; j * (7 * i - 1) + i < 42857; j++) {
      a[j * (7 * i - 1) + i][0] = 2;
      a[j * (7 * i - 1) - i][1] = 2;
    }
  end1:;
    if (a[i][1] == 2)
      goto end2;
    for (int j = 1; j < i / 2 + 1; j++) {
      if (a[j][0] == 1) {
        if ((7 * i + 1) % (7 * j - 1) == 0) {
          a[i][1] = 2;
          goto end2;
        }
      }
      if (a[j][1] == 1) {
        if ((7 * i + 1) % (7 * j + 1) == 0) {
          a[i][1] = 2;
          goto end2;
        }
      }
    }
    a[i][1] = 1;
    for (int j = 1; j * (7 * i + 1) + i < 42857; j++) {
      a[j * (7 * i + 1) + i][1] = 2;
      a[j * (7 * i + 1) - i][0] = 2;
    }
  end2:;
  }
  while (cin >> n) {
    if (n == 1)
      break;
    int y[100] = {0}, ct = 0;
    for (int i = 1; i < n / 7 + 3; i++) {
      if (a[i][0] == 1 && n % (7 * i - 1) == 0) {
        y[ct] = 7 * i - 1;
        ct++;
      }
      if (a[i][1] == 1 && n % (7 * i + 1) == 0) {
        y[ct] = 7 * i + 1;
        ct++;
      }
    }
    cout << n << ":";
    int a = 0;
    while (y[a] > 0) {
      cout << " " << y[a];
      a++;
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int n;
  int a[42857][2];
  a[1][0] = 1;
  a[1][1] = 1;
  for (int i = 2; i <= 42857; i++) {
    for (int j = 1; j < i; j++) {
      if (a[j][0] == 1) {
        if ((7 * i - 1) % (7 * j - 1) == 0) {
          a[i][0] = 0;
          goto end1;
        }
      }
      if (a[j][1] == 1) {
        if ((7 * i - 1) % (7 * j + 1) == 0) {
          a[i][0] = 0;
          goto end1;
        }
      }
    }
    a[i][0] = 1;
  end1:;
    for (int j = 1; j < i; j++) {
      if (a[j][0] == 1) {
        if ((7 * i + 1) % (7 * j - 1) == 0) {
          a[i][1] = 0;
          goto end2;
        }
      }
      if (a[j][1] == 1) {
        if ((7 * i + 1) % (7 * j + 1) == 0) {
          a[i][1] = 0;
          goto end2;
        }
      }
    }
    a[i][1] = 1;
  end2:;
  }
  while (cin >> n) {
    if (n == 1)
      break;
    int y[100] = {0}, ct = 0;
    for (int i = 1; i < n / 7 + 3; i++) {
      if (a[i][0] == 1 && n % (7 * i - 1) == 0) {
        y[ct] = 7 * i - 1;
        ct++;
      }
      if (a[i][1] == 1 && n % (7 * i + 1) == 0) {
        y[ct] = 7 * i + 1;
        ct++;
      }
    }
    cout << n << ":";
    int a = 0;
    while (y[a] > 0) {
      cout << " " << y[a];
      a++;
    }
    cout << endl;
  }
  return 0;
}