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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 100000000000007
using namespace std;
using pii = pair<int, int>;
using LL = int64_t;

vector<pair<int64_t, int64_t>> fs; // 素因数分解の素数，指数のペア

void prime_factorize(LL N) {
  // vector<pair<LL, LL>> res;
  for (LL a = 2; a * a <= N; a++) {
    if (N % a == 0) {
      LL ex = 0; // 指数

      // 割れる限り割り続ける
      while (N % a == 0) {
        ++ex;
        N /= a;
      }

      fs.push_back(make_pair(a, ex));
    }
  }

  // 最後に残った数について
  if (N != 1)
    fs.push_back(make_pair(N, 1));
}

void factorization(int64_t base) { // baseを素因数分解
  // base未満のiが約数か
  for (int i = 2; i * i <= base; i++) {
    // iで割り切れるなら限界まで割る

    if (base % i == 0) {
      int64_t cnt = 0;
      while (base % i == 0) {
        base /= i;
        cnt++;
      }
      fs.push_back(make_pair(i, cnt));
    }
  }
  // baseが素数
  if (base > 1) {
    fs.push_back(make_pair(base, 1));
  }
}
int main() {
  int64_t n;
  cin >> n;

  // factorization(n);
  prime_factorize(n);
  int64_t ans = 0;
  for (auto p : fs) {
    int64_t e;
    e = p.second;
    int k = 1;
    while (e - k >= 0) {
      e -= k;
      k++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 100000000000007
using namespace std;
using pii = pair<int, int>;
using LL = int64_t;

vector<pair<int64_t, int64_t>> fs; // 素因数分解の素数，指数のペア

void prime_factorize(LL N) {
  vector<pair<LL, LL>> res;
  for (LL a = 2; a * a <= N; a++) {
    if (N % a == 0) {
      LL ex = 0; // 指数

      // 割れる限り割り続ける
      while (N % a == 0) {
        ++ex;
        N /= a;
      }

      res.push_back(make_pair(a, ex));
    }
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back(make_pair(N, 1));
  fs = res;
}

void factorization(int64_t base) { // baseを素因数分解
  // base未満のiが約数か
  for (int i = 2; i * i <= base; i++) {
    // iで割り切れるなら限界まで割る

    if (base % i == 0) {
      int64_t cnt = 0;
      while (base % i == 0) {
        base /= i;
        cnt++;
      }
      fs.push_back(make_pair(i, cnt));
    }
  }
  // baseが素数
  if (base > 1) {
    fs.push_back(make_pair(base, 1));
  }
}
int main() {
  int64_t n;
  cin >> n;

  factorization(n);
  // prime_factorize(n);
  int64_t ans = 0;
  for (auto p : fs) {
    int64_t e;
    e = p.second;
    int k = 1;
    while (e - k >= 0) {
      e -= k;
      k++;
      ans++;
    }
  }

  cout << ans << endl;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 100000000000007
using namespace std;
using pii = pair<int, int>;
using LL = int64_t;

vector<pair<int64_t, int64_t>> fs; // 素因数分解の素数，指数のペア

vector<pair<LL, LL>> prime_factorize(LL N) {
  vector<pair<LL, LL>> res;
  for (LL a = 2; a * a <= N; a++) {
    if (N % a != 0)
      continue;
    LL ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    res.push_back(make_pair(a, ex));
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back(make_pair(N, 1));
  return res;
}

void factorization(int64_t base) { // baseを素因数分解
  // base未満のiが約数か
  for (int i = 2; i * i <= base; i++) {
    // iで割り切れるなら限界まで割る

    if (base % i == 0) {
      int cnt = 0;
      while (base % i == 0) {
        base /= i;
        cnt++;
      }
      fs.push_back(make_pair(i, cnt));
    }
  }
  // baseが素数
  if (base > 1) {
    fs.push_back(make_pair(base, 1));
  }
}
int main() {
  int64_t n;
  cin >> n;

  // factorization(n);
  auto res = prime_factorize(n);
  int64_t ans = 0;
  for (auto p : res) {
    int64_t e;
    e = p.second;
    int k = 1;
    while (e - k >= 0) {
      e -= k;
      k++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 100000000000007
using namespace std;
using pii = pair<int, int>;

vector<pair<int64_t, int64_t>> fs; // 素因数分解の素数，指数のペア
void factorization(int64_t base) { // baseを素因数分解
  // base未満のiが約数か
  for (int i = 2; i * i <= base; i++) {
    // iで割り切れるなら限界まで割る
    if (base % i != 0) {
      continue;
    }
    if (base % i == 0) {
      int cnt = 0;
      while (base % i == 0) {
        base /= i;
        cnt++;
      }
      fs.push_back(make_pair(i, cnt));
    }
  }
  // baseが素数
  if (base > 1) {
    fs.push_back(make_pair(base, 1));
  }
}
int main() {
  int64_t n;
  cin >> n;

  factorization(n);
  int64_t ans = 0;
  for (auto p : fs) {
    int64_t e;
    e = p.second;
    int k = 1;
    while (e - k >= 0) {
      e -= k;
      k++;
      ans++;
    }
  }

  cout << ans << endl;

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

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

int main() {
  long n;
  cin >> n;
  long a = 2;
  int c, s;
  c = 0;
  s = 0;
  while (n >= a * a) {
    if (n % a == 0) {
      n /= a;
      c++;
    } else {
      if (c > 0) {
        for (int i = 1; i < 15; ++i) {
          c -= i;
          if (c < 0)
            break;
          else
            s++;
        }
      }
      a++;
      c = 0;
    }
  }
  if (n == a)
    c++;
  for (int i = 1; i < 15; ++i) {
    c -= i;
    if (c < 0)
      break;
    else
      s++;
  }
  if (n != a && n > 1)
    s++;

  cout << s << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long n;
  cin >> n;
  long a = 2;
  int c, s;
  c = 0;
  s = 0;
  while (n >= a) {
    if (n % a == 0) {
      n /= a;
      c++;
    } else {
      if (c > 0) {
        for (int i = 1; i < 15; ++i) {
          c -= i;
          if (c < 0)
            break;
          else
            s++;
        }
      }
      a++;
      c = 0;
    }
  }
  for (int i = 1; i < 15; ++i) {
    c -= i;
    if (c < 0)
      break;
    else
      s++;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define f(i, j, k) for (int i = j; i < k; i++)
#define f2(i, j, k) for (int i = j; i >= k; i--)
int main() {
  long long n, ans = 0;
  cin >> n;
  long long nn = sqrt(n);
  for (long long i = 2; i <= nn; i++) {
    long long j = 0, top = 1;
    while (n % i == 0) {
      n /= i;
      j++;
      if (j >= top) {
        j = 0;
        top++;
        ans++;
      }
    }
  }
  if (n != 1) {
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define f(i, j, k) for (int i = j; i < k; i++)
#define f2(i, j, k) for (int i = j; i >= k; i--)
int main() {
  long long n, ans = 0;
  cin >> n;
  long long num = n;
  long long nn = sqrt(n);
  for (int i = 2; i <= nn; i++) {
    long long j = 0, top = 1;
    while (num % i == 0) {
      n /= i;
      j++;
      if (j >= top) {
        j = 0;
        top++;
        ans++;
      }
    }
  }
  if (num != 1) {
    ans++;
  }
  cout << ans << endl;

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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll a[1000006] = {0};
int main(void) {
  ll n;
  scanf("%lld", &n);
  ll n1 = n;
  for (ll i = 2; i * i <= n; i++) {
    if (n1 % i == 0) {
      ll cnt = 0;
      while (n1 % i == 0)
        n1 /= i, cnt++;
      a[i] = cnt;
    }
  }

  ll ans = 0;
  if (n1 > 1)
    ans++;
  for (ll i = 2; i * i <= n; i++) {
    if (a[i] != 0) {
      for (ll j = 1; j <= n; j++) {
        if (j * (j + 1) / 2 > a[i])
          break;
        ans++;
      }
    }
  }
  printf("%lld", ans);
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll a[100006] = {0};
int main(void) {
  ll n;
  scanf("%lld", &n);
  ll n1 = n;
  for (ll i = 2; i * i <= n; i++) {
    if (n1 % i == 0) {
      ll cnt = 0;
      while (n1 % i == 0)
        n1 /= i, cnt++;
      a[i] = cnt;
    }
  }
  ll ans = 0;
  if (n1 > 1)
    ans++;
  for (ll i = 2; i * i <= n; i++) {
    if (a[i] != 0) {
      for (ll j = 1; j <= n; j++) {
        if (j * (j + 1) / 2 > a[i])
          break;
        ans++;
      }
    }
  }
  printf("%lld", ans);
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
LL BinaryModularPower(LL x, LL y, LL mod) {
  int z = y & 1;
  LL p = x, v = 1;
  while (y) {
    if (y & 1) {
      v = (v * p) % mod;
    }
    p = (p * p) % mod;
    y >>= 1;
  }
  return v;
}
int Prime(LL a, LL b, LL x, LL mod) {
  LL y = BinaryModularPower(a, b, x);
  if (y == 1)
    return 1;
  while (x) {
    if (y + 1 == mod) {
      return 1;
    }
    y = (y * y) % mod;
    x--;
  }
  return 0;
}
int main(void) {
  LL a = 0, i = 3, p = 2, N = IN();
  if (N == 1)
    return puts("0"), 0;
  while (p * p < N) {
    int count = 0;
    LL y = i >> 1, loop = 1;
    while (!(N % p)) {
      count++, N /= p;
    }
    a += e[count];
    if (i == 3 || i == 5 || i == 7 || i == 11) {
      p++;
      continue;
    }
    while (!(y & 1)) {
      y >>= 1;
      loop++;
    }
    if (Prime(2, y, loop, i) && Prime(3, y, loop, i) && Prime(5, y, loop, i) &&
        Prime(7, y, loop, i) && Prime(11, y, loop, i)) {
      p++;
    }
    i += 2;
  }
  if (N > 1) {
    a++;
  }
  return printf("\\n%lld\\n", a), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57)
    f ^= c == 45, c = getchar();
  while (c > 47 && c < 58)
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
int main(void) {
  int x = 0;
  LL a = 0, i, N = IN();
  while (N % 2 == 0) {
    x++;
    N /= 2;
  }
  a += e[x], x = 0;
  while (N % 3 == 0) {
    x++;
    N /= 3;
  }
  a += e[x], x = 0;
  for (i = 0; i * i <= N; i += 6) {
    x = 0;
    while (!i && (!(N % (i + 1)))) {
      x++, N /= i + 1;
    }
    a += e[x];
    x = 0;
    while (N % (i + 5) == 0) {
      x++, N /= i + 5;
    }
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57)
    f ^= c == 45, c = getchar();
  while (c > 47 && c < 58)
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
int main(void) {
  int x = 0;
  LL a = 0, i, N = IN();
  while (N % 2 == 0) {
    x++;
    N /= 2;
  }
  a += e[x], x = 0;
  while (N % 3 == 0) {
    x++;
    N /= 3;
  }
  a += e[x], x = 0;
  while (N % 5 == 0) {
    x++;
    N /= 5;
  }
  a += e[x];
  for (i = 6; i * i <= N; i += 6) {
    x = 0;
    while (N % (i + 1) == 0) {
      x++, N /= i + 1;
    }
    a += e[x];
    x = 0;
    while (N % (i + 5) == 0) {
      x++, N /= i + 5;
    }
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57)
    f ^= c == 45, c = getchar();
  while (c > 47 && c < 58)
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
int main(void) {
  int x = 0;
  LL a = 0, i, N = IN();
  while (N % 2 == 0) {
    x++;
    N /= 2;
  }
  a += e[x], x = 0;
  while (N % 3 == 0) {
    x++;
    N /= 3;
  }
  a += e[x], x = 0;
  while (N % 5 == 0) {
    x++;
    N /= 5;
  }
  a += e[x];
  for (i = 0; i * i <= N; i += 6) {
    x = 0;
    while (N % (i + 1) == 0) {
      x++, N /= i + 1;
    }
    a += e[x];
    x = 0;
    while (N % (i + 5) == 0) {
      x++, N /= i + 5;
    }
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
LL N;
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57)
    f ^= c == 45, c = getchar();
  while (c > 47 && c < 58)
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
int main(void) {
  int i, x = 0;
  long long a = 0, N;
  N = IN();
  while (N % 2 == 0) {
    x++;
    N /= 2;
  }
  a += e[x];
  for (i = 3; (LL)i * i <= N; i += 2) {
    x = 0;
    while (!(N % i))
      x++, N /= i;
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}

Error: 0

Fixed submission:

#include <math.h>
#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
int box[100] =
    {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
},
    pos = 0;
LL N;
void Wheel(LL n) {
  LL ws[11] = {1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6};
  LL f = 2;
  int w = 0;
  while (f * f <= n) {
    if (n % f == 0) {
      n /= f;
      box[pos]++;
    } else {
      f += ws[w];
      w = (w == 10) ? 3 : (w + 1);
      pos++;
    }
  }
  box[pos]++;
  return;
}
int main(void) {
  int x;
  LL a = 0;
  x = scanf("%lld", &N) - 1;
  Wheel(N);
  for (x = 0; x <= pos; x++) {
    a += e[box[x]];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
int main(void) {
  int i, x;
  long long a = 0, N;
  x = scanf("%lld", &N) - 1;
  while (N % 2 == 0) {
    x++;
    N /= 2;
  }
  a += e[x];
  for (i = 3; i <= 1e6; i += 2) {
    x = 0;
    while (!(N % i))
      x++, N /= i;
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
int main(void) {
  int i, x;
  long long a = 0, N;
  x = scanf("%lld", &N);
  x = 0;
  while (N % 2 == 0)
    x++, N /= 2;
  a += e[x];
  for (i = 3; i * i <= N; i += 2) {
    x = 0;
    while (!(N % i))
      x++, N /= i;
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
int main(void) {
  int p, j, x;
  long long a = 0, N;
  x = scanf("%lld", &N);
  for (p = 2; p <= 1e6; p++) {
    for (x = 0; N % p == 0; x++)
      N /= p;
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, p, r, x;
  long long N;
  a = scanf("%lld", &N) - 1;
  for (p = 2; p * p < N; p++) {
    for (x = 0; N % p == 0; x++)
      N /= p;
    for (r = 0; r * (r + 1) / 2 <= x; r++)
      ;
    a += r - 1;
  }
  if (N - 1)
    a++;
  return printf("%d\\n", a), 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#include <cmath>
#include <iostream>

unsigned long long int ans = 0;

unsigned long long int stair(unsigned long long int &a) {
  unsigned long long int i = 0;
  while (a > i) {
    a -= (i + 1);
    i++;
  }
  return i;
}

int main(int argc, char const *argv[]) {
  unsigned long long int N;
  std::cin >> N;
  unsigned long long int two_pow = 0;
  int tmp2 = 1;
  while (N % 2 == 0) { // 偶数の素数は2のみ
    two_pow += 1;
    if (two_pow >= tmp2) {
      two_pow -= tmp2;
      tmp2 += 1;
      ans += 1;
    }

    N /= 2;
  }
  unsigned long long int three_pow = 0;
  int tmp3 = 1;
  while (N % 3 == 0) { // 偶数の素数は2のみ
    three_pow++;
    if (three_pow >= tmp3) {
      three_pow -= tmp3;
      tmp3 += 1;
      ans += 1;
    }
    N /= 3;
  }
  unsigned long long i_max = sqrt(N) + 1e6;
  for (unsigned long long int i = 5; i <= i_max && i <= N; i += 2) {
    if ((i % 3) == 0)
      continue;
    if ((N % i) == 0) {
      unsigned long long int n_pow = 0; // 指数カウンタクリア
      int tmp = 1;
      do {
        n_pow++; // 指数カウンタプラス
        if (n_pow >= tmp) {
          n_pow -= tmp;
          tmp += 1;
          ans += 1;
        }
        N /= i;

      } while ((N % i) == 0);
      // ans += stair(n_pow);
    }
  }
  if (N != 1)
    ans++;
  std::cout << ans << std::endl;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <iostream>

unsigned long long int ans = 0;

unsigned long long int stair(unsigned long long int &a) {
  unsigned long long int i = 0;
  while (a > i) {
    a -= (i + 1);
    i++;
  }
  return i;
}

int main(int argc, char const *argv[]) {
  unsigned long long int N;
  std::cin >> N;
  unsigned long long int two_pow = 0;
  int tmp2 = 1;
  while (N % 2 == 0) { // 偶数の素数は2のみ
    two_pow += 1;
    if (two_pow >= tmp2) {
      two_pow -= tmp2;
      tmp2 += 1;
      ans += 1;
    }

    N /= 2;
  }
  unsigned long long int three_pow = 0;
  int tmp3 = 1;
  while (N % 3 == 0) { // 偶数の素数は2のみ
    three_pow++;
    if (three_pow >= tmp3) {
      three_pow -= tmp3;
      tmp3 += 1;
      ans += 1;
    }
    N /= 3;
  }

  for (unsigned long long int i = 5; i <= N; i += 2) {
    if ((i % 3) == 0)
      continue;
    if ((N % i) == 0) {
      unsigned long long int n_pow = 0; // 指数カウンタクリア
      int tmp = 1;
      do {
        n_pow++; // 指数カウンタプラス
        if (n_pow >= tmp) {
          n_pow -= tmp;
          tmp += 1;
          ans += 1;
        }
        N /= i;

      } while ((N % i) == 0);
      // ans += stair(n_pow);
    }
  }
  std::cout << ans << std::endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs;
  for (ll i = 2; i * i <= n; ++i) {
    int x = 0;
    while (n % i == 0) {
      n /= i;
      ++x;
    }
    fs.emplace_back(i, x);
  }
  if (n != 1)
    fs.emplace_back(n, 1);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int soin(int n) {
  int cnt = 0;
  int a = 2;
  while (n >= a) {
    if (n % a == 0) {
      n /= a;
      cnt++;
    }
    a++;
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  cout << soin(n) << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'

// 素因数分解
map<long long, int> primeMap(ll N) {
  map<long long, int> z;
  for (ll i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      z[i]++;
      N /= i;
    }
  }
  if (N != 1)
    z[N]++;
  return z;
}

int main() {
  ll N;
  cin >> N;
  map<ll, int> z = primeMap(N);
  /*
  for(const auto& p:z){
      cout << p.first << " " << p.second << endl;
  }
  */
  int count = 0;
  for (const auto &p : z) {
    for (long j = 1; p.second > 0; j++) {
      if (p.second >= j * (j + 1) / 2)
        count++;
      else
        break;
    }
  }
  fin(count);

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
/*

*/

int main() {
  ll N;
  cin >> N;
  ll Nconst = N;
  ll ans = 0;
  if (Nconst == 1) {
    fin(0);
    return 0;
  }
  // 素数判定
  bool prime = 1;
  for (ll a = 2; a * a <= N; a++) {
    if (N % a == 0) {
      prime = 0;
      break;
    }
  }
  if (prime) {
    fin(1);
    return 0;
  }
  for (long long a = 2; a <= N; a++) {
    // if(a * a > Nconst) break;
    // cout << "a = " << a << endl;
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数
    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    // cout << "ex = " << ex << endl;
    // cout << "N= " << N << endl;
    // N は aのexを含む
    for (long j = 1; ex > 0; j++) {
      ex -= j;
      if (ex >= 0)
        ans++;
    }
    if (a >= 3)
      a++;
  }
  if (ans)
    fin(ans);
  else
    fin(1);
  return 0;
}