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

#include <bits/stdc++.h>

using namespace std;

// void get_from_key(multimap<string, int> m, string key) {
//   auto p = m.equal_range(key);
//   for (auto itr = p.first; itr != p.second; itr++) {
//     cout << itr->second << endl;
//   }
// }

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  multimap<string, int> m;

  int cmd, val;
  string lhd, rhd;
  string key;

  for (int i = 0; i < n; i++) {
    cin >> cmd;

    switch (cmd) {
    case 0:
      cin >> key >> val;
      // m[key] = val;
      m.insert(make_pair(key, val));
      break;

    case 1: {
      cin >> key;
      // get_from_key(m, key);
      multimap<string, int>::iterator itr = m.lower_bound(key);
      multimap<string, int>::iterator end = m.upper_bound(key);

      for (; itr != end; itr++) {
        cout << itr->second << endl;
      }

      break;
    }

    case 2:
      cin >> key;
      m.erase(key);
      break;

    case 3: {
      cin >> lhd >> rhd;

      multimap<string, int>::iterator end = m.upper_bound(rhd);
      for (auto itr = m.lower_bound(lhd); itr != end; itr++) {
        cout << itr->first << " " << itr->second << endl;
      }
      break;
    }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void get_from_key(multimap<string, int> m, string key) {
  auto p = m.equal_range(key);
  for (auto itr = p.first; itr != p.second; itr++) {
    cout << itr->second << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  multimap<string, int> m;

  int cmd, val;
  string lhd, rhd;
  string key;

  for (int i = 0; i < n; i++) {
    cin >> cmd;

    switch (cmd) {
    case 0:
      cin >> key >> val;
      // m[key] = val;
      m.insert(make_pair(key, val));
      break;

    case 1:
      cin >> key;
      get_from_key(m, key);

      break;

    case 2:
      cin >> key;
      m.erase(key);
      break;

    case 3:
      cin >> lhd >> rhd;

      multimap<string, int>::iterator end = m.upper_bound(rhd);
      for (auto itr = m.lower_bound(lhd); itr != end; itr++) {
        cout << itr->first << " " << itr->second << endl;
      }
      break;
    }
  }
}
Problem p02462 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
using namespace std;

signed main() {
  multimap<string, int> map;
  int q;
  cin >> q;
  while (q--) {
    int y;
    string k;
    cin >> y >> k;
    if (y == 0) {
      int x;
      cin >> x;
      map.insert(pair<string, int>(k, x));
    } else if (y == 1) {
      for (auto it = map.find(k); it != map.end() && it->first == k; it++) {
        cout << it->second << endl;
      }
    } else if (y == 2) {
      map.erase(k);
    } else {
      string z;
      cin >> z;
      for (auto it = map.lower_bound(k); it != map.upper_bound(z); it++) {
        cout << it->first << " " << it->second << endl;
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
using namespace std;

signed main() {
  multimap<string, int> map;
  int q;
  cin >> q;
  while (q--) {
    int y;
    string k;
    cin >> y >> k;
    if (y == 0) {
      int x;
      cin >> x;
      map.insert(pair<string, int>(k, x));
    } else if (y == 1) {
      for (auto it = map.find(k); it->first == k; it++) {
        cout << it->second << endl;
      }
    } else if (y == 2) {
      map.erase(k);
    } else {
      string z;
      cin >> z;
      for (auto it = map.lower_bound(k); it != map.upper_bound(z); it++) {
        cout << it->first << " " << it->second << endl;
      }
    }
  }
  return 0;
}
Problem p02462 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
multimap<string, int> mp;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int Q;
    cin >> Q;
    string s, l, r;
    int x;
    if (Q == 0) {
      cin >> s >> x;
      mp.insert(make_pair(s, x));
    }
    if (Q == 1) {
      cin >> s;
      for (auto it = mp.lower_bound(s); it != mp.end() && it->first == s;
           it++) {
        cout << it->second << endl;
      }
    }
    if (Q == 2) {
      cin >> s;
      mp.erase(s);
    }
    if (Q == 3) {
      cin >> l >> r;
      auto now = mp.lower_bound(l);
      auto end = mp.upper_bound(r);
      assert(l <= r);
      while (now != end) {
        cout << now->first << " " << now->second << endl;
        ++now;
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
multimap<string, int> mp;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int Q;
    cin >> Q;
    string s, l, r;
    int x;
    if (Q == 0) {
      cin >> s >> x;
      mp.insert(make_pair(s, x));
    }
    if (Q == 1) {
      cin >> s;
      auto now = mp.lower_bound(s);
      while (now->first == s && now != mp.end()) {
        cout << now->second << endl;
        ++now;
      }
    }
    if (Q == 2) {
      cin >> s;
      mp.erase(s);
    }
    if (Q == 3) {
      cin >> l >> r;
      auto now = mp.lower_bound(l);
      auto end = mp.upper_bound(r);
      assert(l <= r);
      while (now != end) {
        cout << now->first << " " << now->second << endl;
        ++now;
      }
    }
  }
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  int N, n;
  bool flg = false;

  cin >> N;
  cout << N << ":";

  n = N;
  while (n != 1) {

    flg = false;
    for (int i = 2; i * i <= N; i++) {
      if (n % i == 0) {
        n /= i;
        cout << " " << i;
        flg = true;
        break;
      }
    }

    if (!flg) {
      cout << " " << n;
      n /= n;
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int N, n;

  cin >> N;
  cout << N << ":";

  n = N;
  while (n != 1) {

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

#include <iostream>
#include <sstream>
#include <string>

int main() {
  unsigned int n;
  std::stringstream ss;
  std::cin >> n;
  ss << n << ": ";
  for (unsigned int i = 2; i * i <= n; i++) {
    if (!(n % i)) {
      n /= i;
      ss << i << " ";
      i = 1;
    }
  }
  if (n != 1)
    ss << n << " ";

  std::string s = ss.str();
  std::cout << s.substr(0, s.size() - 1) << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>

int main() {
  unsigned int n;
  std::stringstream ss;
  std::cin >> n;
  ss << n << ": ";
  for (unsigned int i = 2; n != 1; i++) {
    if (!(n % i)) {
      n /= i;
      ss << i << " ";
      i = 1;
    }
  }
  std::string s = ss.str();
  std::cout << s.substr(0, s.size() - 1) << std::endl;

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

#include <iostream>
using namespace std;

int judge(long long n) {
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  if (n % 2 == 0)
    return 0;
  for (int i = 3; i <= n / i; i += 2) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  long long n;

  cin >> n;
  cout << n << ":";
  if (judge(n))
    cout << " " << n;
  else {
    for (int i = 2; i <= n; i++) {
      if (n % i == 0) {
        cout << " " << i;
        n /= i;
        i--;
      }
    }
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n, m;

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

  for (int i = 2; i <= m; i++) {
    if (m % i == 0) {
      cout << " " << i;
      m /= i;
      i--;
    }
  }
  if (n == m)
    cout << " " << 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;
  cout << n << ": ";
  for (int i = 2; n >= i * i; i++) {
    if (n % i == 0) {
      cout << i << " ";
      n /= i;
      i--;
    }
  }
  cout << n << endl;
}


Error: TLE

Fixed submission:

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

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

int main() {
  std::istream &c_in = cin;
  int n;
  c_in >> n;
  cout << n << ":";

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

Error: TLE

Fixed submission:

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

int main() {
  std::istream &c_in = cin;
  int n;
  c_in >> n;
  cout << n << ":";

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

// #include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

int main() {

  int n;
  cin >> n;
  vi fac;

  cout << n << ":";
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      fac.pb(i);
      n = n / i;
    }
  }
  if (n != 1)
    fac.pb(n);

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
/*
void PrimeList(vector<int> &v) {
        v[0] = 1;
        v[1] = 1;
        for (int i = 2; i <= sqrt(MOD-7); i++) {
                if (v[i] == 0) {
                        for (int j = 2; j <= sqrt(MOD-7); i++) {
                                v[i*j] = 1;

                        }
                }
        }
        cout << "hog" << endl;

        vi list;
        for (int i = 0; i < v.size(); i++) {
                if (v[i] == 0) {
                        list.pb(i);;
                }
        }

        v = list;
        return;
}
*/

bool isPrime(int num) {
  if (num <= 1)
    return false;
  if (num == 2)
    return true;

  for (int i = 2; i <= sqrt(num); i++) {
    if (num % 2 == 0) {
      return false;
    }
  }
  return true;
}

int main() {

  vector<int> P;

  vi fac;
  int n;
  cin >> n;
  int tmp = n;

  int idx = 2;
  while (tmp != 1) {

    if (tmp % idx == 0 and isPrime(idx)) {
      tmp = tmp / idx;
      fac.pb(idx);
    } else {
      idx++;
    }
  }

  cout << n << ":";
  for (int i = 0; i < fac.size(); i++) {
    cout << " " << fac[i];
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 1000000;

void prime_factor(int n) {
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      printf(" %d", i);
      n /= i;
    }
  }
  if (n != 1) {
    printf(" %d", n);
  }
  return;
}

int main() {
  int n;
  scanf("%d", &n);
  printf("%d:", n);
  prime_factor(n);
  printf("\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N];

void sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }
  return;
}

int main() {
  int n;
  scanf("%d", &n);
  int buff = n;
  sieve(n);
  vector<P> p;
  for (int i = 0; prime[i] <= (int)sqrt(n); i++) {
    int cnt = 0;
    while (buff % prime[i] == 0) {
      buff /= prime[i];
      cnt++;
    }
    if (cnt > 0) {
      p.push_back(P(prime[i], cnt));
    }
    if (is_prime[buff]) {
      p.push_back(P(buff, 1));
      break;
    }
  }
  printf("%d:", n);
  rep(i, p.size()) {
    rep(j, p[i].second) { printf(" %d", p[i].first); }
  }
  printf("\\n");
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>

using namespace std;

void prime_factor(int n) {
  int d = n;
  for (int i = 2; i * i <= d; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }

  if (n != 1)
    cout << " " << n;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  cout << n << ":";
  prime_factor(n);
  cout << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>

using namespace std;

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

  int d = n;
  int i;
  for (i = 2; i <= d; i++) {
    while (n % i == 0) {
      ret.push_back(i);
      n /= i;
    }
  }
  if (n != 1)
    ret.push_back(d);

  return ret;
}

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

  int n;
  cin >> n;

  vector<int> ans = prime_factor(n);

  sort(ans.begin(), ans.end());
  cout << n << ":";
  for (int i = 0; i < ans.size(); i++) {
    cout << " " << ans[i];
  }
  cout << "\\n";

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

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
bool isPrime(int x) {
  for (int i = 2; i <= sqrt(x); i++)
    if (x % i == 0)
      return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int> res;
  int temp = n;
  if (isPrime(n))
    res.push_back(n);
  else {
    for (int i = 2; i <= n; i++) {
      if (isPrime(i))
        while (temp % i == 0) {
          res.push_back(i);
          temp /= i;
        }
      if (temp == 1)
        break;
    }
  }
  cout << n << ":";
  for (int i = 0; i < res.size(); i++) {
    cout << " ";
    cout << res[i];
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
bool isPrime(int x) {
  for (int i = 2; i <= sqrt(x); i++)
    if (x % i == 0)
      return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int> res;
  int temp = n;
  for (int i = 2; i <= n; i++) {
    if (isPrime(i))
      while (temp % i == 0) {
        res.push_back(i);
        temp /= i;
      }
    if (temp == 1)
      break;
  }
  cout << n << ":";
  for (int i = 0; i < res.size(); i++) {
    cout << " ";
    cout << res[i];
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long div(long long n1) {
  for (long long i = 2; i <= sqrt(n1);) {
    if (n1 % i == 0) {
      return i;
    } else {
      i++;
    }
  }
  return -1;
}

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

  cout << n << ":";

  while (1) {
    if (div(n) == -1) {
      cout << " " << n;
      break;
    }
    cout << " " << div(n);
    n = n / div(n);
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  cout << n << ":";

  for (long long i = 2; i <= n;) {
    if (n % i == 0) {
      cout << " " << i;
      n = n / i;
    } else
      i++;
  }

  cout << endl;

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

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int nn = n;
  cout << n << ":";
  bool cnt = true;
  while (1) {
    if (n % 2 == 0) {
      cout << " " << 2;
      n /= 2;
      cnt = false;
    } else
      break;
  }
  while (1) {
    if (n % 3 == 0) {
      cout << " " << 3;
      n /= 3;
      cnt = false;
    } else
      break;
  }
  for (int i = 3; i <= nn; i += 2) {
    bool gouseisuu = false;
    for (int j = 3; j <= i; j += 2) {
      if (i % j == 0) {
        gouseisuu = true;
        break;
      }
      if (!gouseisuu) {
        while (1) {
          if (n % i == 0) {
            cout << " " << i;
            n /= i;
            cnt = false;
          } else
            break;
        }
      }
    }
    if (n == 1)
      break;
    if (n == nn && cnt == true && i >= sqrt(n))
      break;
  }
  if (cnt)
    cout << " " << nn;
  cout << endl;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int nn = n;
  cout << n << ":";
  bool cnt = true;
  while (1) {
    if (n % 2 == 0) {
      cout << " " << 2;
      n /= 2;
      cnt = false;
    } else
      break;
  }
  while (1) {
    if (n % 3 == 0) {
      cout << " " << 3;
      n /= 3;
      cnt = false;
    } else
      break;
  }
  for (int i = 3; i <= nn; i += 2) {
    bool gouseisuu = false;
    for (int j = 3; j <= i; j += 2) {
      if (i % j == 0) {
        gouseisuu = true;
        break;
      }
      if (!gouseisuu) {
        while (1) {
          if (n % i == 0) {
            cout << " " << i;
            n /= i;
            cnt = false;
          } else
            break;
        }
      }
    }
    if (n == 1)
      break;
  }
  if (cnt)
    cout << " " << nn;
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main(void) {

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define MAX 1000000

using namespace std;

void primeNumber(bool *);

int main(void) {

  int num;
  bool prime[MAX];

  // ??´??°??¨??????
  primeNumber(prime);

  // ??´??°??\\???
  cin >> num;
  cout << num << ":";
  for (int i = 2; i < num; ++i) {
    if (prime[i]) {
      while (num % i == 0) {
        cout << " " << i;
        num /= i;
      }
    }
  }
  if (num != 1) {
    cout << " " << num;
  }
  cout << endl;

  return 0;
}

void primeNumber(bool *prime) {

  for (int i = 0; i < MAX; ++i) {
    prime[i] = true;
  }

  for (int i = 2; i * i < MAX; ++i) {
    if (prime[i]) {
      for (int j = i * i; j < MAX; j += i) {
        prime[j] = false;
      }
    }
  }
}
Problem p02467 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#define F first
#define S second
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define FORI(i, k, n) for (int i = k; i < (int)n; i++)
#define repp(i, k, n) for (int i = k; i < (int)n; i++)
using namespace std;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pip;
typedef unsigned long long ull;
const double EPS = 10e-6;
bool flg[1000005] = {};

int main() {

  int n, ori;
  cin >> n;
  ori = n;
  cout << n << ":";
  for (int i = 2; i <= 1000005; i++) {
    if (flg[i]) {
      ;
    } else {
      for (int l = i; l <= 1000005; l += i) {
        flg[l] = true;
      }
    }
  }
  while (1) {
    if (n == 1) {
      cout << endl;
      break;
    }
    for (int i = 2; i <= 1000005; i++) {
      if (n % i == 0) {
        cout << " " << i;
        n /= i;
        break;
      }
    }
    if (n == ori) {
      cout << " " << ori << endl;
      break;
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#define F first
#define S second
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define FORI(i, k, n) for (int i = k; i < (int)n; i++)
#define repp(i, k, n) for (int i = k; i < (int)n; i++)
using namespace std;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pip;
typedef unsigned long long ull;
const double EPS = 10e-6;
bool flg[100000003] = {};

int main() {

  int n, ori;
  cin >> n;
  ori = n;
  cout << n << ":";
  for (int i = 2; i <= 100000003; i++) {
    if (flg[i]) {
      ;
    } else {
      for (int l = i; l <= 100000003; l += i) {
        flg[l] = true;
      }
    }
  }
  while (1) {
    if (n == 1) {
      cout << endl;
      break;
    }
    for (int i = 2; i < 100000003; i++) {
      if (n % i == 0) {
        cout << " " << i;
        n /= i;
        break;
      }
    }
    if (n == ori) {
      cout << " " << ori << endl;
      break;
    }
  }
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << n << ":";
  int m = n;
  for (int i = 2; i < sqrt(n); i++) {
    for (;;) {
      if (m % i != 0) {
        break;
      } else if (m % i == 0) {
        cout << " " << i;
        m /= i;
      }
    }
    if (m == 1)
      break;
  }
  if (n == m) {
    cout << " " << n << endl;
  } else if (m != 1) {
    cout << " " << m << endl;
  } else {
    cout << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << n << ":";
  for (int i = 2; i < 1000000000; i++) {
    for (;;) {
      if (n % i != 0) {
        break;
      } else if (n % i == 0) {
        cout << " " << i;
        n /= i;
      }
    }
    if (n == 1)
      break;
  }
  cout << endl;
  return 0;
}