alexjercan/bugnet huggingface dataset:
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define N 50000

void eratosthenes(bool prime[N]) {
  for (unsigned long long int i = 0; N > i; ++i)
    prime[i] = 1;
  prime[0] = prime[1] = 0;
  for (unsigned long long int i = 0; N > i; ++i) {
    if (prime[i]) {
      for (unsigned long long int j = i + i; j < N; j += i) {
        prime[j] = 0;
      }
    }
  }
}

bool is_prime(const unsigned n, vector<unsigned long long int> vec) {
  switch (n) {
  case 0: // fall-through
  case 1:
    return false;
  }

  // n > 2 が保証された

  for (auto i : vec) {
    if (i >= n)
      return true;
    if (n % i == 0)
      return false;
  }

  return true;
}

int main() {
  bool prime[N];
  eratosthenes(prime);
  vector<unsigned long long int> vec;
  for (unsigned long long int i = 0; i < N; ++i) {
    if (prime[i]) {
      vec.push_back(i);
    }
  }
  unsigned long long int n;
  cin >> n;
  cout << n << ": ";
  unsigned int pos = 0;
  while (!is_prime(n, vec)) {
    if (n % vec[pos] == 0) {
      n /= vec[pos];
      cout << vec[pos] << " ";
    } else {
      pos++;
    }
  }
  cout << n << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define N 60000

void eratosthenes(bool prime[N]) {
  for (unsigned long long int i = 0; N > i; ++i)
    prime[i] = 1;
  prime[0] = prime[1] = 0;
  for (unsigned long long int i = 0; N > i; ++i) {
    if (prime[i]) {
      for (int j = i + i; j < N; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  bool prime[N];
  eratosthenes(prime);
  vector<unsigned int> vec;
  for (unsigned long long int i = 0; i < N; ++i) {
    if (prime[i]) {
      vec.push_back(i);
    }
  }
  unsigned long long int n;
  cin >> n;
  cout << n << ": ";
  unsigned long long int pos = 0;
  while (n >= N || !prime[n]) {
    if (n % vec[pos] == 0) {
      n /= vec[pos];
      cout << vec[pos] << " ";
    } else {
      pos++;
    }
  }
  cout << n << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

vector<int> factors;
void factorize(int n) {
  factors.clear();

  while (n % 2 == 0) {
    factors.push_back(2);
    n /= 2;
  }

  for (int i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      factors.push_back(i);
      n /= i;
    }
  }

  if (n > 2)
    factors.push_back(n);

  // factors.erase(unique(factors.begin(), factors.end()), factors.end());
}

int main() {
  int n;
  cin >> n;
  factorize(n);
  cout << n << ':';
  for (int i = 0; i < factors.size(); i++)
    cout << ' ' << factors[i];
  cout << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

#define mx 1000000000

bool p[mx];
vector<int> v_prime;

void sieve_algo() {
  for (int i = 0; i <= mx; i++)
    p[i] = 1;

  p[0] = 0;
  p[1] = 0;
  v_prime.push_back(2);

  for (int i = 4; i <= mx; i += 2) {
    p[i] = 0;
  }

  for (int i = 3; i <= mx; i += 2) {

    if (p[i] == 1) {
      v_prime.push_back(i);
      for (int j = i + i; j <= mx; j += i) {
        p[j] = 0;
      }
    }
  }
}
int main() {
  sieve_algo();
  int n;
  cin >> n;
  cout << n << ": " << endl;

  {
    long long a = sqrt((double)n);

    for (int i = 0; v_prime[i] && v_prime[i] <= a; ++i) {
      if (n % v_prime[i] == 0) {

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

        if (n == 1)
          break;
      }
    }
  }
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>

#define maxn 1000005

inline bool isp(int x) {
  if (x == 1)
    return false;
  for (register int i = 2; i * i <= x; ++i) {
    if (x % i == 0)
      return false;
  }
  return true;
}

long long plst[maxn];
bool nisp[maxn];
long long pcnt;

void iit() {
  for (long long i = 2; i < maxn; ++i) {
    if (!nisp[i]) {
      plst[++pcnt] = i;
    }
    for (long long j = 1; j <= pcnt && plst[j] * i < maxn; ++j) {
      nisp[plst[j] * i] = false;
      if (i % plst[j] == 0)
        break;
    }
  }
}

void handle(long long t) {
  int cur = 1;
  std::cout << t << ":";
  while (t >= 1 && cur <= pcnt) {
    if (t >= 1e6 && isp(t)) {
      std::cout << " " << t;
      break;
    }
    if (t % plst[cur] == 0) {
      t /= plst[cur];
      std::cout << " " << plst[cur];
    } else {
      cur++;
    }
  }
  std::cout << std::endl;
}

int main() {
  long long n;
  std::cin >> n;
  iit();
  handle(n);
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
int prime[1100000], primesize, phi[11000000];
bool isprime[11000000];
const int listsize = 1e5;
void getlist() {
  memset(isprime, 1, sizeof(isprime));
  isprime[1] = false;
  for (int i = 2; i <= listsize; i++) {
    if (isprime[i])
      prime[++primesize] = i;
    for (int j = 1; j <= primesize && i * prime[j] <= listsize; j++) {
      isprime[i * prime[j]] = false;
      if (i % prime[j] == 0)
        break;
    }
  }
}
void factor(long long i) {
  int curr = 2;
  while (i != 1) {
    if (i % curr == 0 && isprime[curr]) {
      std::cout << " " << curr;
      i /= curr;
      curr = 2;
    } else {
      curr++;
      while (!isprime[curr] && curr <= 1e5) {
        curr++;
      }
    }
  }
}
int main() {
  getlist();
  long long n;
  std::cin >> n;
  // n=1e9;
  std::cout << n << ":";
  factor(n);
  std::cout << std::endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>
int prime(int num) {
  if (num == 1) {
    return 0;
  }
  int tmp = sqrt(num) + 1;
  for (int i = 2; i < tmp; i++) {
    if (num % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int n, i, j, k;
  scanf("%d", &n);

  printf("%d:", n);
  if (prime(n)) {
    printf(" %d\\n", n);
    return 0;
  }
  for (i = 2; n != 1;) {
    if (n % i != 0) {
      // if(n==2)
      i++;
      // else
      // i+=2;
    } else {
      printf(" %d", i);
      n /= i;
    }
  }
  printf("\\n");
}


Error: -11

Fixed submission:

#include <cstring>
#include <iostream>
#include <string>

using namespace std;
#define N 10000000
int che[N];
int pri[N];
int cnt = 0, n;
void prim() {
  for (int i = 0; i < N; i++) {
    che[i] = 1;
  }
  for (int i = 2; i < N; i++) {
    if (che[i]) {
      pri[cnt++] = i;
    }
    for (int j = 0; j < cnt && pri[j] * i < N; j++) {
      che[pri[j] * i] = 0;
      if (i % pri[j] == 0) {
        break;
      }
    }
  }
  //   for(int i=0;i<100;i++) cout<<pri[i]<<endl;
}
int coo[N];
int main() {
  cin >> n;
  int t = n;
  prim();
  memset(coo, 0, sizeof coo);
  if (n < N && che[n]) {
    cout << n << ": " << n << endl;
    return 0;
  }
  int pos = 0;
  while (n != 1) {
    int i;
    if (n < N && che[n]) {
      coo[pos++] = n;
      break;
    }
    for (i = 0; i < cnt; i++) {
      if (n % pri[i] == 0) {
        coo[pos++] = pri[i];
        break;
      }
    }
    n /= pri[i];
  }
  cout << t << ':';
  for (int i = 0; i < pos; i++) {
    cout << ' ' << coo[i];
  }
  cout << '\\n';
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

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

#include <stdio.h>

int pnCheck(int);

int main() {
  int i, j;
  int data, cod;

  scanf("%d", &data);
  printf("%d:", data);
  cod = data;
  i = 2;
  while (data % i == 0) {
    data /= 2;
    printf(" 2");
  }

  for (i = 3; i <= data && i * i <= cod; i += 2) { //?´???°?????????????????????
    if (pnCheck(i)) {
      while (data % i == 0) {
        data /= i;
        printf(" %d", i);
      }
    }
  }
  if (data != 1)
    printf(" %d", data);
  printf("\\n");
  return 0;
}

int pnCheck(int x) { // depth??????????????????
  // if(x<2)return 0;
  // //?????°???????????????????????´??°??¨????????¨???????¨????
  int i;
  int fl = 0;

  for (i = 3; i * i <= x; i += 2) {
    if (pnCheck(i)) {
      if (fl = (x % i == 0))
        break;
    }
  }
  return !fl;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int pnCheck(int);

int main() {
  int i, j;
  int data;

  scanf("%d", &data);
  printf("%d:", data);

  i = 2;
  while (data % i == 0) {
    data /= 2;
    printf(" 2");
  }

  for (i = 3; i <= data; i += 2) { //?´???°?????????????????????
    if (pnCheck(i)) {
      while (data % i == 0) {
        data /= i;
        printf(" %d", i);
      }
    }
  }
  printf("\\n");
  return 0;
}

int pnCheck(int x) { // depth??????????????????
  // if(x<2)return 0;
  // //?????°???????????????????????´??°??¨????????¨???????¨????
  int i;
  int fl = 0;

  for (i = 3; i * i <= x; i += 2) {
    if (pnCheck(i)) {
      if (fl = (x % i == 0))
        break;
    }
  }
  return !fl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

// ?´??????°????§£

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

bool isPrime(int x) {
  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

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

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

  while (n > 1) {
    for (int i = 2; i <= 50847534; ++i) {
      if (isPrime(n)) {
        cout << " " << n;
        n /= n;
        break;
      }
      if (isPrime(i) && n % i == 0) {
        n /= i;
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

bool isPrime(int x) {
  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

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

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  while (n > 1) {
    for (int i = 2; i <= 50847534; ++i) {
      if (isPrime(i) && n % i == 0) {
        n /= i;
        cout << " " << i;
        break;
      }
    }
  }
  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 << ":";
  int i = 2;
  while (n != 1) {
    if (n % i == 0) {
      n /= i;
      cout << " " << i;
    } else if (n < i * i) // nが大きい素数である場合がありO(√n)が最適解
    {
      cout << " " << n;
      break;
    } else {
      i++;
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

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

  return true;
}

int main() {
  int n, f = 2;
  scanf("%d", &n);
  printf("%d:", n);

  while (n != 1) {
    if (n % f == 0) {
      printf(" %d", f);
      n /= f;
    } else
      f++;
  }

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

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

using namespace std;

int n[2], result[100];

int main() {
  scanf("%d", &n[0]);

  n[1] = n[0];

  int a = 2;
  int b = 0;

  while (n[1] > 1) {
    if (n[1] % a == 0) {
      result[b] = a;
      n[1] /= a;
      b++;
    } else {
      a++;
    }

    if (result[b] == 0 && a > sqrt(n[1])) {
      result[b] = n[1];
      b++;
      break;
    }
  }

  printf("%d:", n[0]);
  for (int x = 0; x < b - 1; x++) {
    printf(" %d", result[x]);
  }
  printf(" %d\\n", result[b - 1]);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>

using namespace std;

int n[2], result[100];

int main() {
  scanf("%d", &n[0]);

  n[1] = n[0];

  int a = 2;
  int b = 0;

  while (n[1] > 1) {
    if (n[1] % a == 0) {
      result[b] = a;
      n[1] /= a;
      b++;
    } else {
      a++;
    }
  }

  printf("%d:", n[0]);
  for (int x = 0; x < b - 1; x++) {
    printf(" %d", result[x]);
  }
  printf(" %d\\n", result[b - 1]);

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
#pragma warning(disable : 4018)
#define INT_MAX 2147483647

using namespace std;

bool judge_prime_numbers(int n) {
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  else {
    bool judge = true;
    for (int i = 3; i <= sqrt(n); i = i + 2) {
      if (n % i == 0) {
        judge = false;
        break;
      }
    }
    return judge;
  }
}

void make_new_prime_numbers(vector<int> *ary) {
  int n = (*ary).back() + 2;
  while (true) {
    bool judge = true;
    for (int i = 1; i < (*ary).size(); i++) {
      if (n < pow((*ary)[i], 2))
        break;
      if (n % (*ary)[i] == 0) {
        judge = false;
        break;
      }
    }
    if (judge)
      break;
    n += 2;
  }
  (*ary).push_back(n);
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  vector<int> ret;
  vector<int> prime_numbers{2, 3};
  while (n % 2 == 0) {
    n /= 2;
    ret.push_back(2);
  }
  if (n != 1) {
    while (!judge_prime_numbers(n)) {
      if (n % prime_numbers.back() == 0) {
        n /= prime_numbers.back();
        ret.push_back(prime_numbers.back());
      } else
        make_new_prime_numbers(&prime_numbers);
    }
    ret.push_back(n);
  }
  for (int i = 0; i < ret.size(); i++)
    cout << " " << ret[i];
  cout << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
#pragma warning(disable : 4018)
#define INT_MAX 2147483647

using namespace std;

bool judge_prime_numbers(int n) {
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  else {
    bool judge = true;
    for (int i = 3; i <= sqrt(n); i = i + 2) {
      if (n % i == 0) {
        judge = false;
        break;
      }
    }
    return judge;
  }
}

void make_new_prime_numbers(vector<int> *ary) {
  int n = (*ary).back() + 2;
  while (true) {
    bool judge = true;
    for (int i = 1; i < (*ary).size(); i++) {
      if (n < pow((*ary)[i], 2))
        break;
      if (n % (*ary)[i] == 0) {
        judge = false;
        break;
      }
    }
    if (judge)
      break;
    n += 2;
  }
  (*ary).push_back(n);
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  vector<int> ret;
  vector<int> prime_numbers{2, 3};
  while (n % 2 == 0) {
    n /= 2;
    ret.push_back(2);
  }
  while (!judge_prime_numbers(n)) {
    if (n % prime_numbers.back() == 0) {
      n /= prime_numbers.back();
      ret.push_back(prime_numbers.back());
    } else
      make_new_prime_numbers(&prime_numbers);
  }
  ret.push_back(n);
  for (int i = 0; i < ret.size(); i++)
    cout << " " << ret[i];
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

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

  int i = 2;
  int odd = 0;
  while (i <= n) {
    if (n % i == 0) {
      std::cout << " " << i;
      n /= i;
      i = 2;
      odd = 0;
    } else {
      if (i == 2 && odd == 0) {
        odd = 1;
        i = 3;
      } else if (i > n / 2) {
        i = n;
      } else {
        if (odd == 1)
          i += 2;
        else
          i++;
      }
    }
  }
  std::cout << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

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

  int i = 2;
  while (i <= n) {
    if (n % i == 0) {
      std::cout << " " << i;
      n /= i;
      i = 2;
    } else if (i > n / 2) {
      i = n;
    } else {
      i++;
    }
  }
  std::cout << std::endl;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {
  int n;
  int dp[100001];
  int pos = 1;

  cin >> n;
  cout << n << ":";
  FOR(i, 2, n) {
    if (pos == 1 && i > sqrt(n)) {
      dp[pos] = n;
      pos++;
      n = 1;
    }
    while (n % i == 0) {
      dp[pos] = i;
      pos++;
      n /= i;
    }
  }
  FOR(i, 1, pos - 1) { cout << " " << dp[i]; }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {
  int n;
  int dp[100001];
  int pos = 1;

  cin >> n;
  cout << n << ":";
  FOR(i, 2, n) {
    while (n % i == 0) {
      dp[pos] = i;
      pos++;
      n /= i;
    }
  }
  FOR(i, 1, pos - 1) { cout << " " << dp[i]; }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

std::vector<uint32_t> getPrimeFact(uint32_t);

int main() {
  uint32_t n;
  std::cin >> n;
  std::vector<uint32_t> &&fact = getPrimeFact(n);
  std::cout << n << ": ";
  for (uint32_t i = 0; i < fact.size(); i++) {
    if (i < fact.size() - 1) {
      std::cout << fact[i] << " ";
    } else {
      std::cout << fact[i] << std::endl;
    }
  }
}

std::vector<uint32_t> getPrimeFact(uint32_t n) {
  std::vector<uint32_t> fact;
  uint32_t n_sq = sqrt(n);
  while (n > 1) {
    for (uint32_t i = 2; i <= n_sq; i++) {
      if (n % i == 0) {
        fact.push_back(i);
        n /= i;
        break;
      }
      if (i == n_sq) {
        fact.push_back(n);
        n = 1;
      }
    }
  }
  return fact;
}

Error: TLE

Fixed submission:

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

std::vector<uint32_t> getPrimeFact(uint32_t);

int main() {
  uint32_t n;
  std::cin >> n;
  std::vector<uint32_t> &&fact = getPrimeFact(n);
  std::cout << n << ": ";
  for (uint32_t i = 0; i < fact.size(); i++) {
    if (i < fact.size() - 1) {
      std::cout << fact[i] << " ";
    } else {
      std::cout << fact[i] << std::endl;
    }
  }
}

std::vector<uint32_t> getPrimeFact(uint32_t n) {
  std::vector<uint32_t> fact;
  while (n > 1) {
    for (uint32_t i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        fact.push_back(i);
        n /= i;
        break;
      }
      if (i == (uint32_t)sqrt(n)) {
        fact.push_back(n);
        n = 1;
      }
    }
  }
  return fact;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  int sq = sqrt(n) + 1;
  for (int i = 3; i <= sq; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n, p;
  vector<int> factor;

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

  if (isPrime(n)) {
    factor.push_back(n);
  } else {
    p = 2;
    while (n != 1) {
      if (n % p == 0) {
        n /= p;
        factor.push_back(p);

        if (isPrime(n)) {
          factor.push_back(n);
          break;
        }
      } else {
        ++p;
      }
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  int sq = sqrt(n) + 1;
  for (int i = 3; i <= sq; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n, p;
  vector<int> factor;

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

  p = 2;
  while (n != 1) {
    if (n % p == 0) {
      n /= p;
      factor.push_back(p);

      if (isPrime(n)) {
        factor.push_back(n);
        break;
      }
    } else {
      ++p;
    }
  }

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

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

#include <iostream>
#include <vector>

using namespace std;

vector<int> factorize(const int n) {
  vector<int> ps;

  int tmp = n;
  while (tmp % 2 == 0) {
    ps.push_back(2);
    tmp /= 2;
  }
  for (int i = 3; 2 * i <= n; i += 2) {
    while (tmp % i == 0) {
      ps.push_back(i);
      tmp /= i;
    }
  }
  if (ps.size() == 0)
    ps.push_back(n);

  return ps;
}

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

  vector<int> ps = factorize(n);
  cout << n << ':';
  for (vector<int>::iterator it = ps.begin(); it != ps.end(); ++it) {
    cout << ' ' << *it;
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

vector<int> factorize(int n) {
  vector<int> ps;
  for (int i = 2; n != 1; ++i) {
    while (n % i == 0) {
      ps.push_back(i);
      n /= i;
    }
  }
  return ps;
}

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

  vector<int> ps = factorize(n);
  cout << n << ':';
  for (vector<int>::iterator it = ps.begin(); it != ps.end(); ++it) {
    cout << ' ' << *it;
  }
  cout << endl;

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

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

int main() {
  long long int N;
  cin >> N;
  cout << N << ":";
  if (N <= 1) {
    cout << " " << N << endl;
    return 0;
  }
  long long int M = sqrtl(N) + 1;
  for (size_t i = 2; i <= M; i++) {
    while (N % i == 0) {
      cout << " " << i;
      N /= i;
    }
  }
  if (N != 1) {
    cout << " " << N;
  }
  cout << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  long long int N;
  cin >> N;
  cout << N << ":";
  if (N <= 1) {
    cout << " " << N << endl;
    return 0;
  }
  vector<bool> x(N, true);
  long long int M = sqrtl(N) + 1;
  for (size_t i = 2; i <= M; i++) {
    while (N % i == 0) {
      cout << " " << i;
      N /= i;
    }
  }
  if (N != 1) {
    cout << " " << N;
  }
  cout << endl;
  return 0;
}