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

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

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  int m = sqrt(n);
  while (n % 2 == 0) {
    n /= 2;
    cout << " " << 2;
  }

  int i = 3;
  while (i <= m) {
    if (n % i == 0) {
      cout << " " << i;
      n /= i;
    } else {
      i += 2;
    }
  }
  if (n != 1) {
    cout << " " << n;
  }
  cout << endl;
}


Error: TLE

Fixed submission:

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

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

  int i = 2;
  while (n > 1) {
    if (n % i == 0) {
      cout << " " << i;
      n /= i;
    } else {
      i++;
    }
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> factorize;
  cout << n << ": ";
  int input = n;
  for (int i = 2; i <= sqrt((double)input); ++i) {
    while (n % i == 0) {
      n /= i;
      factorize.push_back(i);
    }
  }
  if (n != 1) {
    factorize.push_back(n);
  }
  for (int i = 0; i < factorize.size() - 1; ++i) {
    cout << factorize[i] << " ";
  }
  cout << factorize[factorize.size() - 1] << endl;
}

int main() {
  solve();
  return (0);
}

Error: 0

Fixed submission:

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

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> factorize;
  cout << n << ": ";
  int input = n;
  for (int i = 2; i <= sqrt((double)input); ++i) {
    while (n % i == 0) {
      n /= i;
      factorize.push_back(i);
    }
  }
  for (int i = 0; i < factorize.size() - 1; ++i) {
    cout << factorize[i] << " ";
  }
  cout << factorize[factorize.size() - 1] << endl;
}

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

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

void Factorization(int v) {
  int k = 2;
  while (v != 1 && k <= sqrt((double)v)) {
    if (v % k == 0) {
      v = v / k;
      if (v == 1) {
        cout << " " << k;
        return;
      }
      Factorization(k);
      k = 2;
    } else
      k++;
  }
  cout << " " << v;
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  Factorization(n);
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

void Factorization(int v) {
  int k = 2;
  while (v != 1) {
    if (v % k == 0) {
      v = v / k;
      if (v == 1) {
        cout << " " << k;
        break;
      }
      Factorization(k);
      k = 2;
    } else
      k++;
  }
}

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  m = n;
  cout << n << ':';

  for (int i = 2; i * i < m; 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, m;
  cin >> n;
  m = n;
  cout << n << ':';
  for (int i = 2; n != 1;) {
    if (n % i == 0) {
      cout << ' ' << i;
      n /= i;
    }
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  return 0;
}


Error: TLE

Fixed submission:

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

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

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

#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int n;
  vector<int> G;
  scanf("%d", &n);
  if (n == 1) {
    printf("%d: %d\\n", n, n);
    return 0;
  }
  int a = n;
  for (int i = 2; i * i <= n; i++) {
    while (a % i == 0) {
      G.push_back(i);
      a /= i;
    }
  }
  if (a != 1)
    G.push_back(a);
  printf("%d:", n);
  for (int i = 0; i < G.size(); i++) {
    printf(" %d", G[i]);
  }
  puts("");
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <vector>
using namespace std;
bool check(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  vector<int> G;
  scanf("%d", &n);
  if (check(n)) {
    printf("%d: %d\\n", n, n);
    return 0;
  }
  int i = 2;
  int a = n;
  while (i < n) {
    if (a % i == 0) {
      if (check(i)) {
        G.push_back(i);
        a /= i;
      } else
        i++;
    } else
      i++;
  }
  printf("%d:", n);
  for (int i = 0; i < G.size(); i++) {
    printf(" %d", G[i]);
  }
  puts("");
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;

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

Error: MLE

Fixed submission:

#include <vector>

std::vector<bool> Eratosthenes(int n) {
  std::vector<bool> is_prime(n + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; is_prime[i] && i * i <= n; ++i)
    for (int j = i << 1; j <= n; j += i)
      is_prime[j] = false;
  return is_prime;
}

////////////////////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  auto is_prime = Eratosthenes(n);
  cout << n << ":";
  for (int i = 2; i * i < is_prime.size(); ++i) {
    if (!is_prime[i])
      continue;
    while (!(n % i)) {
      n /= i;
      cout << " " << i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  int ren = n;
  for (int i = 1; i <= sqrt(n); i++) {
    while (ren != 1) {
      if (ren % (i + 1) == 0) {
        cout << " " << i + 1;
        ren = ren / (i + 1);
      } else
        break;
    }
  }

  if (ren != 1) {
    cout << " " << ren;
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  int ren = n;
  for (int i = 1; i < n; i++) {
    while (ren != 1) {
      if (ren % (i + 1) == 0) {
        cout << " " << i + 1;
        ren = ren / (i + 1);
      } else
        break;
    }
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(int argc, char *argv[]) {
  int a, n;
  scanf("%d", &n);
  printf("%d:", n);
  a = 2;
  while (n >= a * a) {
    if (n % a == 0) {
      printf(" %d", a);
      n = n / a;
    } else {
      a++;
    }
  }
  printf(" %d\\n", n);
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int i, m, d;
  scanf("%d", &d);
  printf("%d:", d);
  m = d % 2;
  while (m == 0) {
    printf(" %d", 2);
    d = d / 2;
    m = d % 2;
  }
  for (i = 3; i <= d; i += 2) {
    m = d % i;
    while (m == 0) {
      printf(" %d", i);
      d = d / i;
      m = d % i;
    }
  }
  printf("\\n");
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int a, b;
  scanf("%d", &a);
  printf("%d:", a);
  b = 2;
  while (a >= b * b) {
    if (a % b == 0) {
      printf(" %d", b);
      a = a / b;
    } else {
      b++;
    }
  }
  printf(" %d\\n", a);
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int i, m, d;
  scanf("%d", &d);
  printf("%d:", d);
  m = d % 2;
  while (m == 0) {
    printf(" %d", 2);
    d = d / 2;
    m = d % 2;
  }
  for (i = 3; i <= d; i += 2) {
    m = d % i;
    while (m == 0) {
      printf(" %d", i);
      d = d / i;
      m = d % i;
    }
  }
  printf("\\n");
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a, t) for (int a = 0; a < t; ++a)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll Sqrt = (ll)sqrt(n);
  cout << n << ":";
  bool flag = false;
  for (ll i = 2; i <= Sqrt; i++) {

    while (n % i == 0) {
      flag = true;
      cout << " " << i;
      n /= i;
    }
  }
  if (n != 1) {
    cout << " " << n;
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a, t) for (int a = 0; a < t; ++a)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll Sqrt = (ll)sqrt(n);
  cout << n << ":";
  for (ll i = 2; i <= n; 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 <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {

  long long n, i;
  cin >> n;
  cout << n << ":";
  i = 2;
  while (n > 1 && i * i <= n) {
    if (n % i == 0) {
      cout << " " << i;
      n /= i;
    } else
      i += 1;
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<long long> dp;

// 素数だったらtrue
bool isprime(long long n) {
  if (find(dp.begin(), dp.end(), n) != dp.end())
    return true;
  if (n == 1)
    return false;
  vector<long long>::iterator itr = dp.begin();
  while (itr != dp.end())
    if (n % (*itr++) == 0)
      return false;
  dp.push_back(n);
  return true;
}

int main() {

  long long n, i;
  queue<long long> ans;

  cin >> n;
  cout << n << ":";
  // 素因数分解部
  i = 2;
  while (n > 1) {
    if (n % i == 0) {
      if (isprime(i))
        ans.push(i);
      n = n / i;
    } else {
      i++;
    }
  }
  if (i * i == n && isprime(i))
    ans.push(i);

  // 結果出力部
  while (!ans.empty()) {
    cout << " " << ans.front();
    ans.pop();
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for (ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for (ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

const int max = 1000000010;
/*bool isPrime[max];

void init(){
        //rep(i, max)isPrime[i] = true;
        isPrime[0] = isPrime[1] = true;

        REP(i, 2, max){
                if (!isPrime[i]){
                        for (int j = i * 2; j < max; j += i)isPrime[j] = true;
                }
        }
}*/

int main() {
  // init();

  int n;
  std::cin >> n;

  std::cout << n << ":";
  // if (!isPrime[n])std::cout << " " << n;
  // else{
  int cp = n;
  for (int i = 2; i * i <= cp; ++i) {
    while (n % i == 0)
      n /= i, std::cout << " " << i;
  }
  //}
  if (n != 1)
    std::cout << " " << n;
  std::cout << std::endl;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for (ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for (ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

const int max = 1000000010;
bool isPrime[max];

void init() {
  // rep(i, max)isPrime[i] = true;
  isPrime[0] = isPrime[1] = true;

  REP(i, 2, max) {
    if (!isPrime[i]) {
      for (int j = i * 2; j < max; j += i)
        isPrime[j] = true;
    }
  }
}

int main() {
  init();

  int n;
  std::cin >> n;

  std::cout << n << ":";
  if (!isPrime[n])
    std::cout << " " << n;
  else {
    int cp = n;
    for (int i = 2; i * i <= cp; ++i) {
      while (n % i == 0)
        n /= i, std::cout << " " << i;
    }
  }
  std::cout << std::endl;

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

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

vector<int> p(0);

void Prime(int n) {

  bool flg[(int)sqrt(pow(10, 9)) + 1];
  int indx = 2;

  flg[0] = flg[1] = 0;
  for (int i = 0; i < sqrt(n) + 1; i++)
    flg[i] = 0;

  while (indx <= sqrt(n)) {
    flg[indx] = 1;
    p.push_back(indx);
    for (int i = 2; i * indx < sqrt(n); i++) {
      flg[indx] = 1;
    }

    while (flg[indx] == 1 && indx <= sqrt(n))
      indx++;
  }
}

int main() {

  int n;

  cin >> n;

  Prime(n);

  cout << n << ':';

  int i = 0;
  while (n != 1 && i < (int)p.size()) {

    while (n % p[i] == 0) {
      cout << ' ' << p[i];
      n /= p[i];
    }

    i++;
  }

  if (i == (int)p.size() && n != 1)
    cout << ' ' << n;
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

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

vector<int> p(0);

void Prime(int n) {

  bool flg[(int)sqrt(pow(10, 9)) + 1];
  int indx = 2;

  flg[0] = flg[1] = 0;
  for (int i = 0; i < sqrt(n) + 1; i++)
    flg[i] = 0;

  while (indx <= sqrt(n)) {
    flg[indx] = 1;
    p.push_back(indx);
    for (int i = 2; i * indx < sqrt(n); i++) {
      flg[indx] = 1;
    }

    while (flg[indx] == 1 && indx <= sqrt(n))
      indx++;
  }
}

int main() {

  int n;

  cin >> n;

  Prime(n);

  cout << n << ':';

  int i = 0;
  while (n != 1) {

    while (n % p[i] == 0) {
      cout << ' ' << p[i];
      n /= p[i];
    }

    i++;
  }

  cout << endl;

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

#include <iostream>
using namespace std;

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 << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

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

void searchPrimeFactor(int n) {
  if (checkPrime(n)) {
    cout << " " << n;
    return;
  } else {
    int i = 2;
    while (i <= n) {
      if (!checkPrime(i))
        continue;
      if (n % i == 0) {
        cout << " " << i;
        n /= i;
        break;
      }
      i++;
    }
    searchPrimeFactor(n);
  }
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  searchPrimeFactor(n);
  cout << '\\n';
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long n;
  cin >> n;
  long x = n;
  cout << x << ":";
  int c = 0;
  long k = 1;

  int i = 2;
  while (i * i <= n && k < n) {
    if (x % i == 0) {
      cout << " " << i;
      k *= i;
      x /= i;
      c++;
    }
    if (x % i != 0) {
      i++;
    }
  }
  if (k != n) {
    cout << " " << n / k;
  }

  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long n;
  cin >> n;
  long x = n;
  cout << x << ":";
  int c = 0;
  long k = 1;

  int i = 2;
  while (i * i <= n * n / 5 && k < n) {
    if (x % i == 0) {
      cout << " " << i;
      k *= i;
      x /= i;
      c++;
    }
    if (x % i != 0) {
      i++;
    }
  }

  if (c == 0)
    cout << " " << n;

  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  map<int, int> mp;

  int nn = n;
  for (int i = 2; i <= (int)sqrt(n); i++) {
    while (nn % i == 0) {
      mp[i]++;
      nn /= i;
    }
  }
  if (nn != 1) {
    mp[nn] = 1;
  }

  cout << n << ':';
  bool f = true;
  for (auto x : mp) {
    for (int i = 0; i < x.second; i++) {
      cout << ' ' << x.first;
    }
  }
  cout << endl;

  return 0;
}


Error: 0

Fixed submission:

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

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

  int A[n + 1];
  fill(A, A + n + 1, 1);
  A[0] = 0;
  A[1] = 0;

  for (int i = 2; i <= (int)sqrt(n); i++) {
    if (A[i]) {
      for (int j = i + i; j <= n; j += i) {
        A[j] = 0;
      }
    }
  }

  int org = n;
  vector<int> B;
  for (int i = 2; i <= n; i++) {
    if (A[i]) {
      if (org % i)
        ;
      else {
        while (true) {
          if (org % i)
            break;
          else {
            org /= i;
            B.push_back(i);
          }
        }
        if (org == 1) {
          break;
        }
      }
    }
  }

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

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

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

int main() {
  int n;
  register int nm;
  vector<int> v;
  cin >> n;
  nm = n;
  for (int i = 2; i <= sqrt(n); i++) {
    if (nm == 1)
      break;
    if (nm % i == 0) {
      v.push_back(i);
      nm /= i;
      i--;
    }
  }
  if (v.empty()) {
    v.push_back(n);
  } else {
    for (int i = (int)sqrt(n); i <= n; i++) {
      if (nm == 1)
        break;
      if (nm % i == 0) {
        v.push_back(i);
        nm /= i;
        i--;
      }
    }
  }

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  register int nm;
  vector<int> v;
  cin >> n;
  nm = n;
  for (int i = 2; i <= n; i++) {
    if (nm == 1)
      break;
    if (nm % i == 0) {
      v.push_back(i);
      nm /= i;
      i--;
    }
  }
  cout << n << ":";
  for (int i = 0; i < v.size(); i++) {
    cout << " " << v[i];
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a = 0, c = 0, i = 0, n = 0;
  cin >> a;
  cout << a << ":";
  i = 2;
  n = a;
  while (i <= sqrt(a)) {
    while (n % i == 0) {
      n = n / i;
      cout << ' ' << i;
      c++;
    }
    i++;
  }
  if (n > sqrt(a) && n < a)
    cout << ' ' << n;
  if (a == n)
    cout << ' ' << a;
  cout << endl;
  // cout << b;
}

Error: TLE

Fixed submission:

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

int main() {
  int a = 0, c = 0, i = 0, n = 0;
  cin >> a;
  cout << a << ":";
  i = 2;
  n = a;
  while (i <= a / 2) {
    while (n % i == 0) {
      n = n / i;
      cout << ' ' << i;
      c++;
    }
    i++;
  }
  if (a == n)
    cout << ' ' << a;
  cout << endl;
  // cout << b;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int n;

int isPrime(int x) {
  int i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}

int main(void) {
  scanf("%d", &n);
  printf("%d:", n);
  for (int i = 2; i * i <= n; i++) {
    // printf("present i's value is %d\\n", i);
    while (1) {
      if (isPrime(i) == false || n % i != 0)
        break;
      printf(" %d", i);
      n /= i;
    }
  }
  if (n != 1)
    printf(" %d", n);
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int isPrime(int x) {
  int i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}

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