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

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

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

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

Error: TLE

Fixed submission:

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

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

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define shosu(x) fixed << setprecision(x)
using namespace std;
typedef pair<int, int> P;

int n;
vector<int> ans;

int main() {
  cin >> n;
  cout << n << ':';
  for (int i = 2; i * i <= n; i++) {
    for (; n % i == 0;) {
      ans.push_back(i);
      n /= i;
    }
  }
  if (n != 1)
    ans.push_back(n);
  int tmp = ans.size();
  for (int i = 0; i < tmp; i++) {
    cout << ' ' << ans[i];
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
using namespace std;
int main() {
  int n;
  vector<int> ans;
  cin >> n;
  cout << n << ':';
  while (n % 2 == 0) {
    ans.push_back(2);
    n /= 2;
  }
  for (int i = 3; i <= n; i += 2) {
    if (n % i == 0) {
      ans.push_back(i);
      n /= i;
      i -= 2;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ' ' << ans[i];
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
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)) {
      cout << " " << i;
      n /= i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  int n;

  cin >> n;

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

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

#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 << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;

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

  for (int i = 0; i < n; i++) {
    while (n % i == 0) {
      cout << i << " " << endl;
    }
  }

  cout << endl;

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

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

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

Error: TLE

Fixed submission:

#include <iostream>

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

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

void createPrimeTable(int *table, int size);

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

  /* 素数表を作る */
  int prime_table[sn + 1];
  createPrimeTable(prime_table, sn + 1);

  vector<int> prime;
  for (int i = 0; i < sn + 1; i++)
    if (prime_table[i])
      prime.push_back(i);

  vector<int>::iterator i;
  // for(i=prime.begin(); i!=prime.end(); i++) cout << *i << endl;

  /* ここから本番 */
  for (i = prime.begin(); i != prime.end();) {
    if (!(n % (*i))) {
      if (n == *i)
        break;
      cout << " " << *i;
      n /= *i;
      continue;
    }
    i++;
  }
  cout << " " << n << endl;

  return 0;
}

void createPrimeTable(int *table, int size) {
  for (int i = 0; i < size; i++)
    table[i] = 1;

  table[0] = table[1] = 0;

  for (int i = 2; i < size; i++) {
    if (table[i]) {
      for (int j = i + i; j < size; j += i) {
        table[j] = 0;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

#define MAX (double)1000000000
#define MAX_PRIME (int)sqrt(MAX) + 1

void createPrimeTable(int *table, int size);

int main() {
  /* 素数表を作る */
  int prime_table[MAX_PRIME];
  createPrimeTable(prime_table, MAX_PRIME);

  vector<int> prime;
  for (int i = 0; i < MAX_PRIME; i++)
    if (prime_table[i])
      prime.push_back(i);

  vector<int>::iterator i;
  // for(i=prime.begin(); i!=prime.end(); i++) cout << *i << endl;

  /* ここから本番 */
  int n;
  cin >> n;
  cout << n << ":";
  while (1) {
    for (i = prime.begin(); i != prime.end();) {
      if (!(n % (*i)) && n != (*i)) {
        cout << " " << *i;
        n /= *i;
        continue;
      } else if (n == *i) {
        cout << " " << n;
        goto L1; // whileを抜ける
      }
      i++;
    }
  }
L1:
  cout << endl;

  return 0;
}

void createPrimeTable(int *table, int size) {
  for (int i = 0; i < size; i++)
    table[i] = 1;

  table[0] = table[1] = 0;

  for (int i = 2; i < size; i++)
    if (table[i])
      for (int j = i + i; j < size; j += i)
        table[j] = 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  cout << n << ":";
  while (n > 1) {
    // 約数を探す
    const double sqrtn = sqrt(n);
    for (int i = 2; i <= sqrtn; i++) {
      if (n % i == 0) {
        // iが約数
        cout << " " << i;
        n /= i;
        goto LAST;
      }
    }
    // nは素数なので終了
    cout << " " << n << endl;
    break;

  LAST:
    0;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int yy(int n) {
  for (int i = 2; i < n; i++)
    if (n % i == 0)
      return i;
  return n;
}

int main(int argc, char *argv[]) {
  if (true || argc >= 2) {
    // int n = atoi(argv[1]);
    int n;
    cin >> n;
    cout << n << ":";
    if (n < 2) {
      cout << " " << n << endl;
    } else {
      while (n > 1) {
        int y = yy(n);
        cout << " " << y;
        n /= y;
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  cout << N << ":";
  while (N != 1) {
    bool f = false;
    for (int i = 2; i * i <= N; i++) {
      if (N % i == 0) {
        cout << " " << i;
        N /= i;
        f = true;
        break;
      }
    }
    if (f == false) {
      cout << " " << N;
      break;
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const long long int MAX = 1e3;
map<long long int, long long int> cnt;
long long int prime[MAX] = {1};
void compute() {
  long long int i, j, k;
  for (i = 1; i < MAX; i++)
    prime[i] = 1;
  for (i = 2; i * i < MAX; i++) {
    if (prime[i]) {
      for (j = 2 * i; j < MAX; j += i)
        prime[j] = 0;
    }
  }
}
int main() {
  long long int a, b, c, n, i, j;
  cin >> n;
  c = n;
  compute();
  //	cout<<"\\n";
  cout << n << ':';
  for (i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      cout << " " << i;
      //			cnt[n/i]++;
      n = n / i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const int MAX = 1e6 + 9;
int cnt[MAX] = {0};
int prime[MAX] = {1};
void compute() {
  int i, j, k;
  for (i = 1; i < MAX; i++)
    prime[i] = 1;
  for (i = 2; i * i < MAX; i++) {
    if (prime[i]) {
      for (j = 2 * i; j < MAX; j += i)
        prime[j] = 0;
    }
  }
}
int main() {
  long long int a, b, c, n, i, j;
  cin >> n;
  c = n;
  compute();
  // cout<<"\\n";
  cout << n << ':';
  for (i = 2; i * i <= n; i++) {
    if (prime[i]) {
      while (n % i == 0) {
        cnt[i]++;
        //	cnt[n/i]++;
        n = n / i;
      }
    }
  }
  cnt[n]++;
  for (i = 2; i < MAX; i++) {
    if (cnt[i]) {
      for (j = 0; j < cnt[i]; j++) {
        cout << " " << i;
      }
    }
  }
  cout << "\\n";
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

template <typename T> bool is_prime(T n) {
  if (n == 2) {
    return true;
  } else if ((n == 1) || (n % 2 == 0)) {
    return false;
  }

  T p = (T)sqrt(n);
  for (T i = 3; i <= p; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

template <typename T> vector<T> prime_factor(T n) {
  vector<T> pf;

  T m = n;
  for (T i = 2; m > 1;) {
    if (m % i == 0) {
      m /= i;
      pf.push_back(i);
    } else {
      if (is_prime(m)) {
        pf.push_back(m);
        return pf;
      } else {
        i++;
      }
    }
  }
  return pf;
}

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

  cout << n << ": ";

  vector<ullong> pf = prime_factor(n);
  for (ullong i = 0; i < pf.size(); i++) {
    cout << pf.at(i) << (i == pf.size() - 1 ? "" : " ");
  }

  cout << endl;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

bool is_prime(int n) {
  if (n == 2) {
    return true;
  } else if ((n == 1) || (n % 2 == 0)) {
    return false;
  }

  int p = (int)sqrt(n);
  for (int i = 3; i <= p; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

vector<int> prime_factor(int n) {
  vector<int> pf;

  for (int i = 2; i <= n;) {
    if (is_prime(i) && n % i == 0) {
      n /= i;
      pf.push_back(i);
    } else {
      i += (i == 2) ? 1 : 2;
    }
  }

  return pf;
}

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

  cout << n << ": ";

  vector<int> pf = prime_factor(n);
  for (int i = 0; i < pf.size(); i++) {
    cout << pf.at(i) << (i == pf.size() - 1 ? "" : " ");
  }

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

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

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << n << ":";
  while (true) {
    if (n % 2 != 0)
      break;
    n /= 2;
    cout << " 2";
  }
  int i = 3;
  while (true) {
    if (n == 1) {
      cout << endl;
      break;
    }
    bool t = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0)
        t = false;
    }
    if (n % i == 0) {
      if (t == true) {
        n /= i;
        if (n == 1) {
          cout << " " << i << endl;
          break;
        }
        cout << " " << i;
      } else
        i += 2;
    } else
      i += 2;
  }
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
inline void prime_fac(int n) {
  int m = (int)floor(sqrt(n) + 0.5);
  for (int i = 2; i <= m; ++i) {
    while (n % i == 0) {
      n /= i;
      cout << " " << i;
    }
  }
  if (n != 1) {
    cout << " " << n;
  }
}
int main() {
  int n;
  cin >> n;
  cout << n << ":";
  prime_fac(n);
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
inline bool is_prime(int n) {
  if (n <= 1)
    return false;
  int m = (int)floor(sqrt(n) + 0.5);
  for (int i = 2; i <= m; ++i) {
    if (n % i == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  cout << n << ": ";
  if ((n <= 1) || (is_prime(n))) {
    cout << n << endl;
    return 0;
  }
  vector<int>::iterator it;
  vector<int> prime;
  int m = n;
  while (n != 1) {
    for (int i = 2; i <= m; ++i) {
      if ((n % i == 0) && (is_prime(i))) {
        n /= i;
        prime.push_back(i);
      }
    }
  }
  sort(prime.begin(), prime.end());
  for (it = prime.begin(); it != prime.end() - 1; ++it) {
    cout << *it << " ";
  }
  cout << prime.back() << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int root(int n) {
  long long t = n;
  while (1) {
    t = (t * t + n) / (2 * t);
    if (t * t <= n)
      return (int)t;
  }
}
int main() {
  int n, i = 5, r, m = 0;
  ;

  cin >> n;
  cout << n << ":";
  while (n % 2 == 0) {
    n /= 2;
    cout << " " << 2;
  }
  if (n == 1) {
    cout << endl;
    return 0;
  }
  while (n % 3 == 0) {
    n /= 3;
    cout << " " << 3;
  }
  if (n == 1) {
    cout << endl;
    return 0;
  }

  r = root(n);
  while (i <= r) {
    if (n % i == 0) {
      cout << " " << i;
      n /= i;
      r = root(n);
    } else {
      if (m ^= 1)
        i += 2;
      else
        i += 4;
    }
  }
  cout << " " << n << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int root(int n) {
  int first, last, t, s;
  first = 0;
  last = n;
  while (first + 1 != last) {
    t = (first + last) / 2;
    s = t * t;
    if (s > n)
      last = t;
    else
      first = t;
  }
  return first;
}
int main() {
  int n, i = 5, r, m = 0;
  ;

  cin >> n;
  cout << n << ":";
  while (n % 2 == 0) {
    n /= 2;
    cout << " " << 2;
  }
  if (n == 1) {
    cout << endl;
    return 0;
  }
  while (n % 3 == 0) {
    n /= 3;
    cout << " " << 3;
  }
  if (n == 1) {
    cout << endl;
    return 0;
  }

  r = root(n);
  while (i <= r) {
    if (n % i == 0) {
      cout << " " << i;
      n /= i;
      r = root(n);
    } else {
      if (m ^= 1)
        i += 2;
      else
        i += 4;
    }
  }
  cout << " " << n << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define MOD 1000000007LL
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int tmp = n;
  cout << n << ':';
  for (int i = 2; i * i <= tmp; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt > 0) {
      REP(j, cnt) cout << ' ' << i;
    }
  }
  if (n != 1)
    cout << ' ' << n;
  cout << endl;

  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define MOD 1000000007LL
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  map<int, int> mp;
  int tmp = n;
  for (int i = 2; i <= n; i++) {
    int cnt = 0;
    while (tmp % i == 0) {
      cnt++;
      tmp /= i;
    }
    mp[i] = cnt;
  }
  if (tmp != 1)
    mp[n] = 1;
  cout << n << ':';
  for (auto itr : mp) {
    REP(i, itr.second) { cout << ' ' << itr.first; }
  }
  cout << endl;

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

#include <iostream>
using namespace std;

int pri(int n) {
  if (n % 2 == 0) {
    cout << " " << 2;
    return n / 2;
  }
  for (int i = 3; i <= n / i; i += 2) {
    if (n % i == 0) {
      cout << " " << i;
      return n / i;
    }
  }

  cout << " " << n;
  return 1;
}

int main() {
  int n;

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

  while (n != 1) {
    n = pri(n);
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int pri(int n) {
  if (n % 2 == 0) {
    cout << " " << 2;
    return n / 2;
  }
  for (int i = 3;; i += 2) {
    if (n % i == 0) {
      cout << " " << i;
      return n / i;
    }
  }
}

int main() {
  int n;

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

  while (n != 1) {
    n = pri(n);
  }

  cout << endl;

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

#include <iostream>
using namespace std;

bool flag[1000010];

int main() {
  int n, p;
  cin >> n;
  p = n;
  cout << n << ":";
  while (1) {
    if (n == 1) {
      cout << endl;
      break;
    }
    for (int i = 2; i < 1000010; i++) {
      if (n % i == 0) {
        cout << " " << i;
        n /= i;
        break;
      }
    }
    if (n == p) {
      cout << " " << p << endl;
      break;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool flag[1000010];

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

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

const int MAX = 31700; // sqrt(1e9)
int sosu[MAX + 1];
void Prime_Factor() {
  for (int i = 2; i <= MAX; i++) {
    if (!sosu[i]) {
      for (int j = i * 2; j <= MAX; j += i) {
        sosu[j] = 1;
      }
    }
  }
}
void Prime_Factorization(int k) { // kを素因数分解
  int pri_num = 0;
  for (int i = 2; i <= MAX; i++) {
    while (!sosu[i] && k % i == 0) {
      cout << " " << i;
      k /= i;
      pri_num++;
    }
  }
  if (pri_num == 0)
    cout << " " << k;
}
int main() {
  int n;
  cin >> n;
  cout << n << ':';
  Prime_Factor();
  Prime_Factorization(n);
  cout << "\\n";
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

void Prime_Factorization(int k) { // kを素因数分解
  for (int i = 2; i <= k; i++) {
    while (k % i == 0) {
      cout << " " << i;
      k /= i;
    }
  }
}
int main() {
  int n;
  cin >> n;
  cout << n << ':';
  Prime_Factorization(n);
  cout << "\\n";
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {

  long long int N, x = 2;

  cin >> N;
  cout << N << ":";
  while (1) { // cout<<"#"<<x<<endl;

    if (x * x > N)
      break;
    if (N % x == 0) {
      cout << " " << x;
      N = N / x;
      x = 0;
    }

    x += 2;
    if (x != 2 && x % 2 == 0)
      x--;
  }

  if (N != 1)
    cout << " " << N;
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {

  long long int N, x = 2;

  cin >> N;
  cout << N << ":";
  while (1) { // cout<<"#"<<x<<endl;
    if (x != 2 && x % 2 == 0)
      x++;
    if (x > N || N == 1)
      break;
    if (N % x == 0) {
      cout << " " << x;
      N = N / x;
      x = 0;
    }

    x += 2;
    if (x != 2 && x % 2 == 0)
      x--;
  }

  if (N != 1)
    cout << " " << N;
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string>
#include <vector>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i, j, n) for (int i = j; i < n; i++)
typedef pair<int, int> P;
struct edge {
  int from, to, cost;
};
double pi = 3.141592653589793;
// 使うやつはここから下に置こうな
signed main() {
  int n;
  cin >> n;
  int t = n;
  cout << n << ":";
  for (int i = 2; i * i <= n; i++) {
    while (t % i == 0) {
      t /= i;
      cout << " " << i;
    }
  }
  if (t != 1)
    cout << " " << t;
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int i, j, k;
  int num;
  cin >> num;
  cout << num << ":";
  while (num % 2 == 0) {
    cout << " " << 2;
    num = num / 2;
  }
  for (i = 3; i <= num; i += 2) {
    k = 0;
    for (j = 3; j <= sqrt(i); j += 2) {
      if (i % j == 0) {
        k = 1;
        break;
      }
    }

    while (k == 0 && num % i == 0) {
      cout << " " << i;
      num = num / i;
    }
  }

  cout << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, i = 2;
  cin >> n;
  cout << n << ':';

  while (i * i <= n) {
    if (n % i != 0) {
      i++;
      continue;
    }
    cout << ' ' << i;
    n /= i;
  }
  cout << ' ' << n << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i = 2;
  cin >> n;
  cout << n << ':';

  while (i <= n) {
    if (n % i != 0) {
      i++;
      continue;
    }
    cout << ' ' << i;
    n /= i;
  }
  cout << endl;

  return 0;
}