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


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

typedef long long ll;
using namespace std;

bool f(int num) {
  if (!(num % 7 == 1 || num % 7 == 6))
    return false;
  for (int i = 2; i < num; i++) {
    if (num % i == 0) {
      if (i % 7 == 1 || i % 7 == 6)
        return false;
    }
  }
  return true;
}

bool solve() {
  int n;
  cin >> n;
  if (n == 1)
    return false;

  cout << n << ":";
  for (int i = 2; i <= n; i++) {
    if ((n % i == 0) && f(i)) {
      cout << " " << i;
    }
  }
  cout << endl;
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  while (solve())
    ;

  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

typedef long long ll;
using namespace std;

const int MAX = 300001;
vector<int> gd;
vector<int> gds;

void ini() {
  for (int i = 2; i < MAX; i++) {
    if (i % 7 == 1 || i % 7 == 6)
      gd.push_back(i);
  }
  for (int i = 0; i < gd.size(); i++) {
    bool f = true;
    for (int j = 0; j < i; j++) {
      if (gd[i] % gd[j] == 0) {
        f = false;
        break;
      }
    }
    if (f)
      gds.push_back(gd[i]);
  }
  //	for(int i=0;i<gds.size();i++) cout<< " "<< gds[i]; cout<< endl;
}

bool solve() {
  int n;
  cin >> n;
  if (n == 1)
    return false;

  cout << n << ":";
  for (int i = 0; i < gds.size(); i++) {
    if (n % gds[i] == 0)
      cout << " " << gds[i];
  }
  cout << endl;
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  ini();
  while (solve())
    ;

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

#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
  int i, j, inp;
  bool flag[300001];

  for (i = 0; i <= 300000; i++) {
    flag[i] = false;
    if (i % 7 == 1 || i % 7 == 6)
      flag[i] = true;
  }
  flag[1] = false;

  for (i = 2; i <= 300000; i++) {
    if (i % 7 == 1 || i % 7 == 6) {
      for (j = 6; j <= sqrt((double)i); j++) {
        if ((j % 7 == 1 || j % 7 == 6) && i % j == 0) {
          flag[i] = false;
          break;
        }
      }
    }
  }

  scanf("%d", &inp);
  while (inp != 1) {
    printf("%d:", inp);
    for (i = 6; i <= inp; i++)
      if (flag[i] && inp % i == 0)
        printf(" %d", i);
    printf("\\n");
    scanf("%d", &inp);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
  int i, j, inp;
  bool flag[300001];

  for (i = 0; i <= 300000; i++) {
    flag[i] = false;
    if (i % 7 == 1 || i % 7 == 6) {
      for (j = 6; j < i; j++) {
        if ((j % 7 == 1 || j % 7 == 6) && i % j == 0)
          break;
      }
      if (i == j)
        flag[i] = true;
    }
  }

  scanf("%d", &inp);
  while (inp != 1) {
    printf("%d:", inp);
    for (i = 6; i <= inp; i++)
      if (flag[i] && inp % i == 0)
        printf(" %d", i);
    scanf("%d", &inp);
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>

using namespace std;

bool prime(int n) {

  for (int i = 6; i < n; i += 7) {
    if (n % i == 0) {
      return false;
    }
  }

  for (int i = 8; i < n; i += 7) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main(void) {

  int n;

  while (1) {
    cin >> n;

    if (n == 1) {
      break;
    }

    cout << n << ":";

    for (int i = 7; i <= n + 1; i = i + 7) {

      if (n % (i - 1) == 0) {
        if (prime(i - 1)) {
          cout << " " << i - 1;
        }
      }

      if (n % (i + 1) == 0) {
        if (prime(i + 1)) {
          cout << " " << i + 1;
        }
      }
    }
    cout << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <string.h>
#define MAX 300001

using namespace std;

bool prime[MAX];
int table[MAX];

int main(void) {

  int n, p, num;

  p = 0;
  memset(prime, true, sizeof(prime));
  memset(table, 0, sizeof(table));

  for (int i = 0; i < 6; i++) {
    prime[i] = false;
  }

  for (int i = 6; i <= MAX; i++) {
    for (int j = 6 * i; j <= MAX; j++) {
      if (prime[i]) {
        table[p++] = i;
        prime[j] = false;
      }
    }
  }

  while (1) {
    cin >> n;
    if (n == 1) {
      break;
    }
    cout << n << ": ";
    for (int i = 0; i < p; i++) {
      if (0 == (n % table[i])) {
        cout << table[i] << " ";
      }
    }
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

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

int sosu[300000];
int main() {

  sosu[1] = 1;
  for (int i = 2; i < 300000; i++) {
    if (i % 7 == 2 || i % 7 == 3 || i % 7 == 4 || i % 7 == 5 || i % 7 == 0) {
      sosu[i] = 1;
      continue;
    }
    int sq = sqrt(i);
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0 && (sosu[j] == 0 || sosu[i / j] == 0)) {
        sosu[i] = 1;
        break;
      }
    }
  }

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

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;
int num[1000001];

bool sosu(int n) {
  if (num[n] == -1)
    return false;
  if (num[n] == 1)
    return true;

  int sqr = sqrt(n);
  for (int i = 2; i <= sqr; i++) {
    if (n % i == 0) {
      num[n] = -1;
      return false;
    }
  }
  num[n] = 1;
  return true;
}

int main() {
  int a, d, n;
  num[1] = -1;
  while (cin >> a >> d >> n, a || d || n) {
    int counter = 0;
    for (int i = a;; i = i + d) {
      if (sosu(i))
        counter++;
      if (counter == n) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int test = 113023;
const int INF = 1e9;
bool prime[300001];
bool is_prime(int n) {
  if (n % 6 == 0)
    return false;
  for (int i = 1; i * i <= n; i++) {
    if (n % (i * 7 + 1) == 0 && i * 7 + 1 != n)
      return false;
    if (n % (i * 7 + 6) == 0 && i * 7 + 6 != n)
      return false;
  }
  return true;
}
int main() {
  int n;
  memset(prime, false, sizeof(prime));
  for (int i = 6; i <= 300000; i++) {
    if (i % 7 == 1 || i % 7 == 6) {
      if (is_prime(i))
        prime[i] = true;
    }
  }
  while (scanf("%d", &n) && n != 1) {
    vector<int> ans;
    printf("%d:", n);
    if (n % 6 == 0)
      ans.PB(6);
    for (int i = 1; i * 7 + 1 <= n; i++) {
      if (n % (i * 7 + 1) == 0)
        if (prime[i * 7 + 1])
          ans.PB(i * 7 + 1);
      if (n % (i * 7 + 6) == 0)
        if (prime[i * 7 + 6])
          ans.PB(i * 7 + 6);
    }
    REP(i, ans.size()) { printf(" %d", ans[i]); }
    puts("");
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1e9;
bool prime[300001];
bool is_prime(int n) {
  if (n % 6 == 0)
    return false;
  for (int i = 1; i * 7 + 6 < n; i++) {
    if (n % (i * 7 + 1) == 0)
      return false;
    if (n % (i * 7 + 6) == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  memset(prime, false, sizeof(prime));
  for (int i = 6; i <= 300000; i++) {
    if (i % 7 == 1 || i % 7 == 6) {
      if (is_prime(i))
        prime[i] = true;
    }
  }
  while (scanf("%d", &n) && n != 1) {
    vector<int> ans;
    printf("%d:", n);
    if (n % 6 == 0)
      ans.PB(6);
    for (int i = 1; i * 7 + 6 <= n; i++) {
      if (n % (i * 7 + 1) == 0)
        if (prime[i * 7 + 1])
          ans.PB(i * 7 + 1);
      if (n % (i * 7 + 6) == 0) {
        if (prime[i * 7 + 6])
          ans.PB(i * 7 + 6);
      }
    }
    REP(i, ans.size()) { printf(" %d", ans[i]); }
    puts("");
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  vector<int> gets;
  vector<int> isge(300001, 1);
  isge[0] = 0;
  isge[1] = 0;
  for (int i = 1; i * 7 - 1 <= 300000; i++) {
    int p = i * 7 - 1;
    if (isge[p]) {
      gets.push_back(p);
      for (int j = p * 2; j <= 300000; j += p)
        isge[j] = 0;
    }
    p = i * 7 + 1;
    if (p > 300000)
      break;
    if (isge[p]) {
      gets.push_back(p);
      for (int j = p * 2; j <= 300000; j += p)
        isge[j] = 0;
    }
  }
  while (cin >> n, n != 1) {
    cout << n << ":";
    for (int j = 0; j < gets.size(); j++)
      if (n % gets[j] == 0)
        cout << " " << gets[j];
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  vector<int> gets;
  for (int i = 1; i * 7 - 1 <= 300000; i++) {
    int p = i * 7 - 1;
    bool isok = true;
    for (int j = 0; j < gets.size(); j++)
      if (p % gets[j] == 0)
        isok = false;
    if (isok)
      gets.push_back(p);
    isok = true;
    if (i * 7 + 1 > 300000)
      break;
    p = i * 7 + 1;
    for (int j = 0; j < gets.size(); j++)
      if (p % gets[j] == 0)
        isok = false;
    if (isok)
      gets.push_back(p);
  }
  while (cin >> n, n != 1) {
    cout << n << ":";
    for (int j = 0; j < gets.size(); j++)
      if (n % gets[j] == 0)
        cout << " " << gets[j];
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

const int MAX = 300000;

int main() {
  int data[MAX + 1];
  // make getuyou_doyou_suu
  for (int i = 0; i < MAX + 1; i++) {
    if (!(i % 7 == 6 || i % 7 == 1))
      data[i] = 1;
    else
      data[i] = 0;
  }
  data[0] = 1;
  data[1] = 1;
  for (int i = 0; i < MAX + 1; i++) {
    if (!data[i]) {
      for (int j = i * 2; j < MAX + 1; j += i)
        data[j] = 1;
    }
  }
  while (1) {
    // input
    int n;
    scanf("%d", &n);
    if (n == 1)
      break;
    set<int> Ans;
    for (int i = 0; i < n + 1; i++)
      if (!data[i] && n % i == 0) {
        Ans.insert(i);
      }
    // output
    set<int>::iterator S = Ans.begin();
    printf("%d:", n);
    while (S != Ans.end()) {
      printf(" %d", *S);
      S++;
    }
    printf("\\n");
  }
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

int amari[30000];

int solve(int c, int n) {
  if (n / amari[c] == 1) {
    return amari[c];
  }
  if (n % amari[c] == 0) {
    solve(c, n / amari[c]);
    solve(c++, n / amari[c]);
  }
  if (n % (amari[c] + 2) == 0) {
    solve(c, n / amari[c] + 2);
    solve(c++, n / amari[c] + 2);
  }
  return 0;
}

int main() {
  int count = 0;
  for (int i = 6; i < 300000; i += 7) {
    amari[count] = i;
    count++;
  }
  while (1) {
    int n;
    scanf("%d", &n);
    if (n == 1)
      break;
    set<int> Ans;
    count = 0;
    Ans.insert(solve(count, n));
    set<int>::iterator S = Ans.begin();
    printf("%d:", n);
    while (S != Ans.end()) {
      printf(" %d", *S);
      S++;
    }
    printf("\\n");
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<vector<long long>> anss;
  vector<long long> soin = {6, 8};
  for (long long i = 2; i * 7 < 60000; i++) {
    int flag = 0;
    for (long long j = 0; soin[j] < i * 7 - 1 && j < soin.size(); j++) {
      if ((i * 7 - 1) % soin[j] == 0)
        flag = 1;
    }
    if (!flag) {
      soin.push_back(i * 7 - 1);
    }
    flag = 0;
    for (long long j = 0; soin[j] < i * 7 + 1 && j < soin.size(); j++) {
      if ((i * 7 + 1) % soin[j] == 0)
        flag = 1;
    }
    if (!flag) {
      soin.push_back(i * 7 + 1);
    }
  }
  vector<long long> sub;
  long long N;
  cin >> N;
  while (N != 1) {
    sub.push_back(N);
    vector<long long> ans;
    for (int i = 0; i < soin.size() && soin[i] <= N / 6; i++) {
      if (N % soin[i] == 0) {
        ans.push_back(soin[i]);
      }
    }
    if (ans.size())
      anss.push_back(ans);
    else
      anss.push_back({N});
    cin >> N;
  }
  for (int i = 0; i < sub.size(); i++) {
    cout << sub[i] << ':';
    for (int j = 0; j < anss[i].size(); j++) {
      cout << ' ' << anss[i][j];
    }
    cout << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<vector<long long>> anss;
  vector<long long> soin = {6, 8};
  for (long long i = 2; i * 7 < 299999; i++) {
    int flag = 0;
    for (long long j = 0; soin[j] < i * 7 - 1 && j < soin.size(); j++) {
      if ((i * 7 - 1) % soin[j] == 0)
        flag = 1;
    }
    if (!flag) {
      soin.push_back(i * 7 - 1);
    }
    flag = 0;
    for (long long j = 0; soin[j] < i * 7 + 1 && j < soin.size(); j++) {
      if ((i * 7 + 1) % soin[j] == 0)
        flag = 1;
    }
    if (!flag) {
      soin.push_back(i * 7 + 1);
    }
  }
  vector<long long> sub;
  long long N;
  cin >> N;
  while (N != 1) {
    sub.push_back(N);
    vector<long long> ans;
    for (int i = 0; i < soin.size() && soin[i] <= N; i++) {
      if (N % soin[i] == 0) {
        ans.push_back(soin[i]);
      }
    }
    anss.push_back(ans);
    cin >> N;
  }
  for (int i = 0; i < sub.size(); i++) {
    cout << sub[i] << ':';
    for (int j = 0; j < anss[i].size(); j++) {
      cout << ' ' << anss[i][j];
    }
    cout << endl;
  }
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

const int size = 300000;

bool a[size] = {false};
std::vector<int> MS;

void eratos() {

  for (int i = 6; i < size; i++)
    a[i] = true;

  for (int i = 6; i < size; i++) {

    if (a[i] && (i % 7 == 1 || i % 7 == 6)) {

      MS.push_back(i);
      for (int j = i + i; j < size; j += i)
        a[j] = false;

    } else
      a[i] = false;
  }
}

void solve(int x) {
  std::vector<int>::iterator it = MS.begin();

  std::cout << x << ':';

  for (; it != MS.end(); ++it)
    if (x % (*it) == 0)
      std::cout << ' ' << *it;

  std::cout << std::endl;
}

int main() {
  int x;

  eratos();

  while (true) {

    std::cin >> x;

    if (x == 1)
      break;

    solve(x);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

const int size = 300000;

bool a[size] = {false};
std::vector<int> MS;

void eratos() {

  for (int i = 6; i < size; i++)
    a[i] = true;

  for (int i = 6; i < size; i++) {

    if (a[i] && (i % 7 == 1 || i % 7 == 6)) {

      MS.push_back(i);
      for (int j = i + i; j < size; j += i)
        a[j] = false;

    } else
      a[i] = false;
  }
}

void solve(int x) {
  std::vector<int>::iterator it = MS.begin();

  std::cout << x << ':';

  for (; it != MS.end(); ++it)
    if (x % (*it) == 0)
      std::cout << ' ' << *it;

  std::cout << std::endl;
}

int main() {
  int x;

  eratos();

  while (true) {

    std::cin >> x;

    if (x == 0)
      break;

    solve(x);
  }

  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Runtime Error

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

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

#define MAXN 300000

vector<int> MSPrimes;
bool isNotMSPrime[MAXN];

void calMSPrime(int n) {
  for (int i = 2; i * n < MAXN; i++) {
    isNotMSPrime[i * n] = true;
  }
}

int main(int argc, const char *argv[]) {

  for (int i = 2; i < MAXN; i++) {
    if (!isNotMSPrime[i] && (i % 7 == 1 || i % 7 == 6)) {
      calMSPrime(i);
      MSPrimes.push_back(i);
    }
  }

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

    set<int> primes;
    for (unsigned id = 0; id < MSPrimes.size() && n >= MSPrimes[id]; id++) {
      if (n % MSPrimes[id] != 0)
        continue;

      int nowId = id, nowN = n;
      while (nowId < MSPrimes.size() && nowN >= MSPrimes[nowId]) {
        int nowPrime = MSPrimes[nowId];
        bool ok = false;

        while (nowN % nowPrime == 0) {
          ok = true;
          nowN /= nowPrime;
        }
        if (ok)
          primes.insert(nowPrime);
        nowId++;
      }
    }

    cout << n << ":";
    for (auto i = primes.begin(); i != primes.end(); i++) {
      cout << " " << *i;
    }
    cout << endl;
    primes.clear();
  }
#if TEST
  fclose(in);
  fclose(out);
#endif
}

Error: 0

Fixed submission:

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

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

#define MAXN 300000

vector<int> MSPrimes;
bool isNotMSPrime[MAXN];

void calMSPrime(int n) {
  for (int i = 2; i * n <= MAXN; i++) {
    isNotMSPrime[i * n] = true;
  }
}

int main(int argc, const char *argv[]) {

  for (int i = 2; i < MAXN; i++) {
    if (!isNotMSPrime[i] && (i % 7 == 1 || i % 7 == 6)) {
      calMSPrime(i);
      MSPrimes.push_back(i);
    }
  }

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

    set<int> primes;
    for (unsigned id = 0; id < MSPrimes.size() && n >= MSPrimes[id]; id++) {
      if (n % MSPrimes[id] != 0)
        continue;

      int nowId = id, nowN = n;
      while (nowId < MSPrimes.size() && nowN >= MSPrimes[nowId]) {
        int nowPrime = MSPrimes[nowId];
        bool ok = false;

        while (nowN % nowPrime == 0) {
          ok = true;
          nowN /= nowPrime;
        }
        if (ok)
          primes.insert(nowPrime);
        nowId++;
      }
    }

    cout << n << ":";
    for (auto i = primes.begin(); i != primes.end(); i++) {
      cout << " " << *i;
    }
    cout << endl;
    primes.clear();
  }
#if TEST
  fclose(in);
  fclose(out);
#endif
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 300000
int n;
bool tf[MAX];
vector<int> prime;

void set(int num) {
  for (int i = num * 2; i < MAX; i += num) {
    tf[i] = true;
  }
}

int main() {
  for (int i = 6; i < MAX; i += 7) {
    if (!tf[i]) {
      set(i);
      prime.push_back(i);
    }
  }
  for (int i = 8; i < MAX; i += 7) {
    if (!tf[i]) {
      set(i);
      prime.push_back(i);
    }
  }
  sort(prime.begin(), prime.end());
  while (1) {
    cin >> n;
    if (n == 1)
      break;
    cout << n << ":";
    for (int i = 0; i < prime.size(); i++) {
      if (n % prime[i] == 0) {
        cout << " " << prime[i];
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
#define MAX 300000
int n;
bool tf[MAX];
vector<int> prime;

void set(int num) {
  for (int i = num * 2; i < MAX; i += num) {
    tf[i] = true;
  }
}

int main() {
  for (int i = 6; i < MAX; i += 7) {
    if (!tf[i]) {
      set(i);
      prime.push_back(i);
    }
  }
  for (int i = 8; i < MAX; i += 7) {
    if (!tf[i]) {
      set(i);
      prime.push_back(i);
    }
  }

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cout << n << ":";
    for (int i = 0; i < prime.size(); i++) {
      if (n % prime[i] == 0) {
        cout << " " << prime[i];
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00735 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 300000;
vector<int> prime;
bool is_prime[MAX_N + 1];

int main(void) {

  for (int i = 0; i <= MAX_N; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MAX_N; i++) {
    if (is_prime[i] && (i % 7 == 1 || i % 7 == 6)) {
      prime.push_back(i);
      for (int j = 2 * i; j <= MAX_N; j += i)
        is_prime[j] = false;
    }
  }

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

    cout << n << ":";
    for (auto d : prime) {
      if (n % d == 0)
        cout << " " << d;
    }
    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 300000;

int main(void) {

  vector<int> gdp;
  for (int i = 1; i <= MAX_N; i++) {
    if (i % 7 == 1 || i % 7 == 6) {
      bool flag = true;
      for (int j = 1; j < gdp.size(); j++) {
        if (i % gdp[j] == 0)
          flag = false;
        if (sqrt(gdp[j]) > i)
          break;
      }
      if (flag)
        gdp.push_back(i);
    }
  }

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

    cout << n << ":";
    for (int i = 1; i < gdp.size(); i++) {
      if (n % gdp[i] == 0)
        cout << " " << gdp[i];
    }
    cout << endl;
  }

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

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 400000;

vector<bool> prime(N, true);

void makePrime() {
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < N; i++) {
    if (!prime[i])
      continue;
    if (i % 7 != 1 && i % 7 != 6) {
      prime[i] = false;
      continue;
    }
    for (int j = i + i; j < N; j += i)
      prime[j] = false;
  }
}

int main() {
  makePrime();
  double n;
  while (cin >> n && n != 1.0) {
    vector<int> ans;
    REP(i, n + 1) if (prime[i] && n / i == (int)(n / i)) { ans.push_back(i); }
    cout << n << ":";
    REP(i, ans.size()) cout << " " << ans[i];
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 500000;

int is_prime[N];
vector<int> prime;

void makePrime() {
  REP(i, N) is_prime[i] = true;
  for (int i = 0; i < N; i++) {
    if (!is_prime[i])
      continue;
    if (i % 7 != 1 && i % 7 == 6) {
      is_prime[i] = false;
      continue;
    }
    prime.push_back(i);
    for (int j = i + i; j < N; j += i)
      is_prime[j] = false;
  }
}

int main() {
  makePrime();
  double n;
  while (cin >> n && n != 1.0) {
    vector<int> ans;
    REP(i, prime.size())
    if (n / prime[i] == (int)(n / prime[i])) ans.push_back(i);
    cout << n << ":";
    REP(i, ans.size()) cout << " " << ans[i];
    cout << endl;
  }
  return 0;
}