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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  long long int n;
  cin >> n;
  long long int m = n;
  cout << n << ":";
  for (int i = 2; i * i < m; i++) {
    while (n % i == 0) {
      n /= i;
      cout << " " << i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;

  return 0;
}

// EOF

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  cout << n << ":";
  int d = 2;
  while (n != 1) {
    if (n % d == 0) {
      n /= d;
      cout << " " << d;
    } else if (d == 2) {
      d++;
    } else {
      d += 2;
    }
  }
  cout << endl;

  return 0;
}

// EOF
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>
#define int long long
using namespace std;
signed main() {
  int n, m;
  vector<int> v;
  cin >> n;
  m = n;
  for (int i = 2; i <= sqrt(n); i++) {
    while (m % i == 0) {
      v.push_back(i);
      m /= i;
    }
  }
  if (m != 1)
    v.push_back(m);
  cout << n << ':';
  for (int i : v)
    cout << ' ' << i;
  cout << endl;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
#define int long long
using namespace std;
signed main() {
  int n, m;
  vector<int> v;
  cin >> n;
  m = n;
  for (int i = 2; i <= sqrt(n); i++) {
    while (m % i == 0) {
      v.push_back(i);
      m /= i;
    }
  }
  if (m >= v.back())
    v.push_back(m);
  cout << n << ':';
  for (int i : v)
    cout << ' ' << i;
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {

  long long a, b;
  cin >> a;
  cout << a << ':';
  b = a;
  for (int i = 2; i * i <= b; i++) {
    while (a % i == 0) {
      cout << ' ' << i;
      a /= i;
    }
    if (a == 1)
      break;
  }
  if (a != 1)
    cout << ' ' << a;
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a;
  cout << a << ':';
  b = a;
  for (int i = 2; i <= b; i++) {
    while (a % i == 0) {
      cout << ' ' << i;
      a /= i;
    }
    if (a == 1)
      break;
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// 素数判定(素数ならtrue)
bool Prime(int prime) {
  // 偶数除く
  if (prime == 2) {
    return true;
  } else if (prime % 2 == 0 || prime < 2) {
    return false;
  }

  float Asqrt = sqrtf(prime);

  for (int i = 3; i <= Asqrt; i += 2) {
    if (prime % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int n;

  cin >> n;

  cout << n << ":";

  for (int prime = 2;; prime++) {

    if (Prime(n)) {
      cout << " " << n << endl;
      break;
    }

    while (true) {
      // 素数 かつ 素因数の場合
      if (Prime(prime) && n % prime == 0) {
        n /= prime;
        cout << " " << prime;

        if (n == 1) {
          cout << endl;
          exit(0);
        }

        // 分解可能なら続ける
        continue;
      }

      // 分解不可でbreak;
      break;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

// 素数判定(素数ならtrue)
bool Prime(int prime) {
  // 偶数除く
  if (prime == 2) {
    return true;
  } else if (prime % 2 == 0 || prime < 2) {
    return false;
  }

  float Asqrt = sqrtf(prime);

  for (int i = 3; i <= Asqrt; i += 2) {
    if (prime % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int n;

  cin >> n;

  cout << n << ":";

  for (int prime = 2;; prime++) {

    if (Prime(n)) {
      cout << " " << n << endl;
      break;
    }

    while (true) {
      // 素数 かつ 素因数の場合
      if (Prime(prime) && n % prime == 0) {
        n /= prime;
        cout << " " << prime;

        // 分解可能なら続ける
        continue;
      }

      // 分解不可でbreak;
      break;
    }
  }

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

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

int main() {
  int n, i;

  cin >> n;

  cout << n << ":";

  for (i = 2; n != 1; i++) {
    if (i > sqrt(n)) {
      cout << " " << n;
      n = 1;
      continue;
    }
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i;

  cin >> n;

  cout << n << ":";

  for (i = 2; n != 1; i++) {
    if (i > n / 2) {
      cout << " " << n;
      n = 1;
      continue;
    }
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  cout << endl;

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

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

int main() {
  int n, i;

  cin >> n;

  cout << n << ":";

  for (i = 2; n != 1; i++) {
    if (i > sqrt(n)) {
      cout << " " << n;
      n = 1;
      continue;
    }
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i;

  cin >> n;

  cout << n << ":";

  for (i = 2; n != 1; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  cout << endl;

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

#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str)                                                           \\
  int str;                                                                     \\
  std::cin >> str;
#define DEBUGING(str) cout << str << endl
const int INF = (1 << 30);

// 毎回変える定数
#define N_MAX 200

// 素因数分解をするアルゴリズム
template <typename T> vector<T> prime_factorization(T n) {
  vector<T> res;
  T check = 2;

  while (check * check <= n) {
    if (n % check == 0) {
      n /= check;
      res.push_back(check);
    } else {
      check++;
    }
  }
  if (n != 1)
    res.push_back(n);
  sort(res.begin(), res.end());
  return res;
}

// 上に、ライブラリを作成していく。
// 問題に応じて、以下を調整する。

// サブ関数
// 入力
void input(int &n) { cin >> n; }

// 出力
void output(int n) {
  cout << n << ":";
  for (auto var : prime_factorization(n)) {
    cout << " " << var;
  }
  cout << endl;
}

// デバッグ
void debug() {
  int N;
  cin >> N;
}

// メイン関数
int main() {
  int n;
  input(n);
  output(n);
  debug();

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str)                                                           \\
  int str;                                                                     \\
  std::cin >> str;
#define DEBUGING(str) cout << str << endl
const int INF = (1 << 30);

// 毎回変える定数
#define N_MAX 200

// 素因数分解をするアルゴリズム
template <typename T> vector<T> prime_factorization(T n) {
  vector<T> res;
  T check = 2;

  while (check <= n) {
    if (n % check == 0) {
      n /= check;
      res.push_back(check);
    } else {
      check++;
    }
  }
  if (n != 1)
    res.push_back(check);
  sort(res.begin(), res.end());
  return res;
}

// 上に、ライブラリを作成していく。
// 問題に応じて、以下を調整する。

// サブ関数
// 入力
void input(int &n) { cin >> n; }

// 出力
void output(int n) {
  cout << n << ":";
  for (auto var : prime_factorization(n)) {
    cout << " " << var;
  }
  cout << endl;
}

// デバッグ
void debug() {
  int N;
  cin >> N;
}

// メイン関数
int main() {
  int n;
  input(n);
  output(n);
  debug();

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

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

bool IsPrime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";

  if (IsPrime(n))
    cout << " " << n;

  else {
    while (IsPrime(n) != true) {
      for (int i = 2; i <= n && n != 1; i++) {
        while (n % i == 0) {
          if (n % i == 0) {
            printf(" %d", i);
            n /= i;
          }
        }
      }
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
#define rep(i, x, to) for (int i; i < 0; i++)

bool IsPrime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";

  for (int i = 2; i <= n && n != 1; i++) {
    while (n % i == 0) {
      if (n % i == 0) {
        printf(" %d", i);
        n /= i;
      }
    }
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve(int n) {
  while (n != 1) {
    cout << " ";
    if (n == 2 || n == 3) {
      cout << n;
      n /= n;
      break;
    }

    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        n /= i;
        cout << i;
        break;
      }
      if (i == (int)sqrt(n)) {
        cout << n;
        n /= n;
        break;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  cout << n << ":";
  solve(n);
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

void solve(int n) {
  while (n != 1) {
    cout << " ";

    if (n == 2 || n == 3) {
      cout << n;
      n /= n;
      break;
    }

    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        n /= i;
        cout << i;
        break;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  cout << n << ":";
  solve(n);
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x = n;
  cout << n << ":";
  for (int i = 2; i * i <= x; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << n << ":";
  for (int i = 2; i < n; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define MAX_N 1 << 9

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  for (int i = 2; i * i <= n; i++)
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  if (n != 1)
    cout << " " << n;
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define MAX_N 1 << 9

typedef long long LL;

bool isPrime(LL n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return n != 1;
}

int main() {
  LL n;
  vector<LL> llv;
  cin >> n;
  for (LL i = 2; i <= MAX_N; i++)
    if (isPrime(i))
      llv.push_back(i);
  cout << n << ":";
  if (isPrime(n)) {
    cout << " " << n << endl;
    return 0;
  }
  for (LL i = 0; n > 1; i++) {
    while (n % llv[i] == 0) {
      cout << " " << llv[i];
      n /= llv[i];
    }
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

bool isPrime(long long x) {
  if (x == 2)
    return true;
  else if ((x < 2) || (x % 2 == 0))
    return false;

  long long i = 3;
  while (i <= sqrt((double)x)) {
    if (x % i == 0)
      return false;
    i += 2;
  }

  return true;
}

int main() {
  long long n;

  cin >> n;
  cout << n << ":";

  while (n % 2 == 0) {
    n /= 2;
    cout << " 2";
  }

  for (long long i = 3; i * i <= n; i += 2) {
    if (isPrime(i)) {
      while (n % i == 0) {
        n /= i;
        cout << " " << i;
      }
    }
  }

  if (n != 1)
    cout << " " << n;

  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

bool isPrime(long x) {
  if (x == 2)
    return true;
  else if ((x < 2) || (x % 2 == 0))
    return false;

  int i = 3;
  while (i <= sqrt((double)x)) {
    if (x % i == 0)
      return false;
    i += 2;
  }

  return true;
}

int main() {
  long n, a = 3;

  cin >> n;
  cout << n << ":";

  while (n % 2 == 0) {
    n /= 2;
    cout << " 2";
  }

  while (n != 1) {
    if (isPrime(a)) {
      if (n % a == 0) {
        n /= a;
        cout << " " << a;
      } else
        a += 2;
    } else
      a += 2;
  }

  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int isprime(int n) {
  if (n < 2)
    return 0;
  else
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0)
        return 0;
    }
  return 1;
} // dfs,
void solve(int n) {
  if (isprime(n)) {
    cout << n << ": " << n << endl; // 特殊情况排除
    return;
  }
  int sum = 0;
  cout << n << ":";
  while (n > 1) {
    for (int i = 2; i <= n; i++)
      if (isprime(i) && (n % i == 0)) {
        cout << " "; // 格式
        cout << i;
        n /= i;
        sum++;
        break;
      }
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  solve(n);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int isprime(int n) {
  if (n < 2)
    return 0;
  else
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0)
        return 0;
    }
  return 1;
} // dfs,
void solve(int n) {
  int sum = 0;
  cout << n << ":";
  while (n > 1) {
    for (int i = 2; i <= n; i++)
      if (isprime(i) && (n % i == 0)) {
        cout << " "; // 格式
        cout << i;
        n /= i;
        sum++;
        break;
      }
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  solve(n);
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

u_int make_prime_list(u_int a[], u_int size) {
  a[0] = 2;
  a[1] = 3;

  u_int i = 2;

  for (u_int q = 5; q <= size; q += 2) {
    u_int threshold = (u_int)sqrt(q);
    bool is_prime = true;

    for (u_int j = 1; a[j] <= threshold; j++)
      if (q % a[j] == 0) {
        is_prime = false;
        break;
      }

    if (is_prime)
      a[i++] = q;
  }

  return i;
}

void prime_factorize(u_int const *prime_list, vector<u_int> *a, u_int n,
                     u_int size) {
  u_int p = 2, i = 1;

  while (p <= n) {
    if (n % p == 0) {
      a->push_back(p);
      n /= p;
    } else if (i < size)
      p = prime_list[i++];
    else
      break;
  }

  if (a->empty() || n != 1)
    a->push_back(n);
}

int main(void) {
  u_int n;
  cin >> n;

  u_int prime_list[100000];
  u_int size = make_prime_list(prime_list, (u_int)sqrt(n));

  vector<u_int> a;
  prime_factorize(prime_list, &a, n, size);

  cout << n << ":";
  for (auto x : a)
    cout << " " << x;
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

void make_prime_list(u_int a[], u_int size) {
  a[0] = 2;
  a[1] = 3;

  u_int i = 2;

  for (u_int q = 5; q <= size; q += 2) {
    u_int threshold = (u_int)sqrt(q);
    bool is_prime = true;

    for (u_int j = 1; a[j] <= threshold; j++)
      if (q % a[j] == 0) {
        is_prime = false;
        break;
      }

    if (is_prime)
      a[i++] = q;
  }
}

void prime_factorize(u_int const *prime_list, vector<u_int> *a, u_int n) {
  u_int p = 2, i = 1;

  while (p <= n) {
    if (n % p == 0) {
      a->push_back(p);
      n /= p;
    } else
      p = prime_list[i++];
  }
}

int main(void) {
  u_int n;
  cin >> n;

  u_int prime_list[100000];
  make_prime_list(prime_list, n);

  vector<u_int> a;
  prime_factorize(prime_list, &a, n);

  cout << n << ":";
  for (auto x : a)
    cout << " " << x;
  cout << endl;

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

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main() {
  int n;
  bool start = true;
  cin >> n;
  cout << n << ": ";
  while (n != 1) {
    if (n % 2 == 0) {
      if (start) {
        cout << 2;
        start = false;
      } else
        cout << " " << 2;
      n /= 2;
    } else {
      bool judge = true;
      for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
          judge = false;
          if (start) {
            cout << i;
            start = false;
          } else
            cout << " " << i;
          n /= i;
          break;
        }
      }
      if (judge) {
        if (start)
          cout << n;
        else
          cout << " " << n;
        n = 1;
      }
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
int main() {
  int n;
  bool start = true;
  cin >> n;
  cout << n << ": ";
  while (n != 1) {
    for (int i = 2; i <= n; i++) {
      if (n % i == 0) {
        if (start) {
          cout << i;
          start = false;
        } else
          cout << " " << i;
        n /= i;
        break;
      }
    }
  }
  cout << endl;

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

#include <iostream>
using namespace std;

int np(int n, int a) {
  int i, k;
  n++;
  if (n == 2)
    return 2;
  if (n % 2 == 0)
    n++;
  while (1) {
    for (int i = n;; i += 2) {
      k = 0;
      for (int j = 3; j * j <= i; j += 2) {
        if (i % j == 0) {
          k = 1;
          break;
        }
      }
      if (k == 0)
        return i;
    }
  }
}

int main() {
  int a, now;
  cin >> a;
  cout << a << ":";
  now = 1;
  while (a != 1) {
    now = np(now, a);
    if (now * now > a) {
      cout << " " << a;
      break;
    }
    while (a % now == 0) {
      cout << " " << now;
      a /= now;
    }
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int np(int n) {
  int i, k;
  n++;
  if (n == 2)
    return 2;
  if (n % 2 == 0)
    n++;
  while (1) {
    for (int i = n;; i += 2) {
      k = 0;
      for (int j = 3; j * j <= i; j += 2) {
        if (i % j == 0) {
          k = 1;
          break;
        }
      }
      if (k == 0)
        return i;
    }
  }
}

int main() {
  int a, now;
  cin >> a;
  cout << a << ":";
  now = 1;
  while (a != 1) {
    now = np(now);
    while (a % now == 0) {
      cout << " " << now;
      a /= now;
    }
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {

  int n;

  cin >> n;
  int max = n;
  printf("%d:", n);

  int i = 2;

  while (n != 1) {
    if (n % i == 0) {
      printf(" %d", i);
      n /= i;
    } else
      break;
  }
  i = 3;
  while (n != 1 && i * i <= max) {
    if (n % i == 0) {
      printf(" %d", i);
      n /= i;
    } else
      i += 2;
  }
  if (n != 1)
    printf(" %d", n);

  printf("\\n");

  // system("pause");
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {

  int n;

  cin >> n;
  printf("%d:", n);

  int i = 2;

  while (n != 1) {
    if (n % i == 0) {
      printf(" %d", i);
      n /= i;
    } else
      break;
  }
  i = 3;
  while (n != 1) {
    if (n % i == 0) {
      printf(" %d", i);
      n /= i;
    } else
      i += 2;
  }
  printf("\\n");

  // system("pause");
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  int n;
  scanf("%d", &n);
  printf("%d:", n);
  for (int i = 2; i * i <= n && n != 1; i++) {
    while (!(n % i)) {
      printf(" %d", i);
      n /= i;
    }
  }
  if (n != 1)
    printf(" %d", n);
  printf("\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int flag = 1, count = 0;
  bool *table;
  long long n, m, tmp[100];
  cin >> n;
  m = n / 2;
  table = new bool[m + 1];
  for (long long i = 0; i <= m; i++)
    table[i] = 1;
  for (long long i = 2; i <= m; i++)
    if (table[i])
      for (long long j = i * 2; j <= m; j += i)
        table[j] = 0;
  cout << n << ":";
  for (long long i = m; i >= 2; i--)
    if (table[i])
      while (!(n % i)) {
        tmp[count] = i;
        count++;
        n /= i;
        flag = 0;
      }
  for (int i = count - 1; i >= 0; i--)
    cout << " " << tmp[i];
  if (flag)
    cout << " " << n;
  cout << endl;

  delete table;

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

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

int N;
int a[1000];
int j = 0;

int main() {
  cin >> N;
  int M = N;
  double n = sqrt(N);
  for (int i = 2; i <= n; i++) {
    while (N % i == 0) {
      N = N / i;
      a[j] = i;
      j++;
    }
  }
  std::cout << M << ":" << std::flush;
  if (j > 0) {
    for (int l = 0; l <= j - 2; l++) {
      std::cout << " " << a[l] << std::flush;
    }
    if (N == 1) {
      cout << " " << a[j - 1] << endl;
    } else {
      cout << " " << a[j - 1] << " " << N << endl;
    }
  } else {
    cout << " " << M << endl;
  }
}

Error: TLE

Fixed submission:

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

int N;
int a[1000];
int j = 0;

int main() {
  cin >> N;
  int M = N;
  for (int i = 2; i <= M; i++) {
    while (N % i == 0) {
      N = N / i;
      a[j] = i;
      j++;
    }
  }
  std::cout << M << ":" << std::flush;
  if (j > 0) {
    for (int l = 0; l <= j - 2; l++) {
      std::cout << " " << a[l] << std::flush;
    }
    cout << " " << a[j - 1] << endl;
  } else {
    cout << " " << M << endl;
  }
}