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

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int isP(int x) {
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0)
      return i;
  }
  return x;
}
void solve() {
  int n;
  cin >> n;
  map<int, int> cnt;
  while (n > 1) {
    cnt[isP(n)]++;
    n /= isP(n);
  }
  int s = 0;
  for (auto i : cnt) {
    int x = (-1 + sqrt(1 + 8 * i.s)) / 2;
    if (x > 0)
      s += x;
  }
  cout << s;
}
signed main() {
  speed;
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int isP(int x) {
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}
void solve() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return;
  }
  if (isP(n)) {
    cout << 1;
    return;
  }
  int id = 2;
  map<int, int> cnt;
  while (n >= id) {
    if (n % id == 0) {
      n /= id;
      cnt[id]++;
    } else
      id++;
  }
  int s = 0, it = 0;
  for (auto i : cnt) {
    int x = (-1 + sqrt(1 + 8 * i.s)) / 2;
    if (x > 0)
      s += x;
  }
  cout << s;
}
signed main() {
  speed;
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void PrimeFactorization(long long n, vector<pair<long long, int>> &f) {
  if (n < 2) {
    pair<long long, int> t;
    t.first = -1;
    f.push_back(t);
    return;
  }
  if (n % 2 == 0) {
    pair<long long, int> t;
    t.first = 2;
    t.second = 0;
    while (n % 2 == 0) {
      t.second++;
      n /= 2;
    }
    f.push_back(t);
  }
  for (long long p = 3; p * p <= n; p += 2) {
    if (n % p == 0) {
      pair<long long, int> t;
      t.first = p;
      t.second = 0;
      while (n % p == 0) {
        t.second++;
        n /= p;
      }
      f.push_back(t);
    }
  }
  if (n != 1) {
    pair<long long, int> t;
    t.first = n;
    t.second = 1;
    f.push_back(t);
  }
}

int main() {
  long long n;
  cin >> n;
  vector<pair<long long, int>> x;
  PrimeFactorization(n, x);

  long long sum = 0;
  for (int i = 0; i < x.size(); i++) {
    for (int j = 1; j <= x[i].second; j++) {
      x[i].second -= j;
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

void PrimeFactorization(long long n, vector<pair<int, int>> &f) {
  if (n < 2) {
    pair<int, int> t;
    t.first = -1;
    f.push_back(t);
    return;
  }
  if (n % 2 == 0) {
    pair<int, int> t;
    t.first = 2;
    t.second = 0;
    while (n % 2 == 0) {
      t.second++;
      n /= 2;
    }
    f.push_back(t);
  }
  for (int p = 3; p * p <= n; p += 2) {
    if (n % p == 0) {
      pair<int, int> t;
      t.first = p;
      t.second = 0;
      while (n % p == 0) {
        t.second++;
        n /= p;
      }
      f.push_back(t);
    }
  }
  if (n != 1) {
    pair<int, int> t;
    t.first = n;
    t.second = 1;
    f.push_back(t);
  }
}

int main() {
  long long n;
  cin >> n;
  vector<pair<int, int>> x;
  PrimeFactorization(n, x);

  long long sum = 0;
  for (int i = 0; i < x.size(); i++) {
    for (int j = 1; j <= x[i].second; j++) {
      x[i].second -= j;
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#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, m;
  bool prime = true;
  cin >> n;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;

    prime = false;
    ll expo = 0;
    while (n % i == 0) {
      n /= i;
      expo++;
    }
    ll j = 1;
    while (expo >= j * (j + 1) / 2)
      j++;
    ans += j - 1;
  }
  if (n != 1)
    ans += 1;
  if (prime)
    ans = 1;
  cout << ans << endl;
  return 0;
}


Error: -8

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 main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 0; i * i <= n; i++) {
    if (n % i != 0)
      continue;

    ll expo = 0;
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      expo++;
      if (cnt == expo) {
        cnt++;
        expo = 0;
      }
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

/**
 *    author:  Dooloper
 *    created: 06.06.2020 00:59:13
 **/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  cin.tie(0);
  ll N;
  cin >> N;
  vector<int> Eratosthenes((int)sqrt(N) + 10, 0);
  vector<int> factor;
  vector<ll> prime;

  /*エラトステネス*/
  for (ll i = 2; i * i < N; i++) {
    if (!Eratosthenes[i]) {
      for (ll j = 2; i * i * j * j <= N; j++)
        Eratosthenes[i * j] = 1;
    }
  }

  for (ll i = 2; i * i < N; i++) {
    prime.emplace_back(i);
  }

  for (ll i : prime) {
    int keep = 0;
    while (N % i == 0) {
      keep++;
      N /= i;
    }
    factor.emplace_back(keep);
  }
  if (N > 1)
    factor.emplace_back(1);

  //     for (int i = 2; i * i < N; i++)
  // {
  //     int keep = 0;
  //     while (N % i == 0)
  //     {
  //         keep++;
  //         N /= i;
  //     }
  //     factor.push_back(keep);
  // }
  // if(N > 1)
  //     factor.push_back(1);

  int ans = 0;
  for (int i : factor) {
    for (int j = 1; j <= i; j++) {
      ans++;
      i -= j;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

/**
 *    author:  Dooloper
 *    created: 06.06.2020 00:59:13
 **/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> Eratosthenes(N + 10, 0);
  vector<int> factor;
  vector<ll> prime;

  /*エラトステネス*/
  for (ll i = 2; i * i < N; i++) {
    if (!Eratosthenes[i]) {
      for (ll j = 2; i * j <= N; j++)
        Eratosthenes[i * j] = 1;
    }
  }

  for (ll i = 2; i * i < N; i++) {
    prime.emplace_back(i);
  }

  for (ll i : prime) {
    int keep = 0;
    while (N % i == 0) {
      keep++;
      N /= i;
    }
    factor.emplace_back(keep);
  }
  if (N > 1)
    factor.emplace_back(1);

  //     for (int i = 2; i * i < N; i++)
  // {
  //     int keep = 0;
  //     while (N % i == 0)
  //     {
  //         keep++;
  //         N /= i;
  //     }
  //     factor.push_back(keep);
  // }
  // if(N > 1)
  //     factor.push_back(1);

  int ans = 0;
  for (int i : factor) {
    for (int j = 1; j <= i; j++) {
      ans++;
      i -= j;
    }
  }

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

/**
 *    author:  Dooloper
 *    created: 06.06.2020 00:59:13
 **/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  cin.tie(0);
  ll N;
  cin >> N;
  vector<int> Eratosthenes((int)sqrt(N) + 10, 0);
  vector<int> factor;
  vector<ll> prime;

  /*エラトステネス*/
  for (ll i = 2; i * i < N; i++) {
    if (!Eratosthenes[i]) {
      for (ll j = 2; i * i * j * j <= N; j++)
        Eratosthenes[i * j] = 1;
    }
  }

  for (ll i = 2; i < Eratosthenes.size(); i++) {
    if (!Eratosthenes[i]) {
      int keep = 0;
      while (N % i == 0) {
        keep++;
        N /= i;
      }
      factor.emplace_back(keep);
    }
  }
  if (N > 1)
    factor.emplace_back(1);

  int ans = 0;
  for (int i : factor) {
    for (int j = 1; j <= i; j++) {
      ans++;
      i -= j;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: -8

Fixed submission:

/**
 *    author:  Dooloper
 *    created: 06.06.2020 00:59:13
 **/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  cin.tie(0);
  ll N;
  cin >> N;
  vector<int> Eratosthenes((int)sqrt(N) + 10, 0);
  vector<int> factor;
  vector<ll> prime;

  /*エラトステネス*/
  for (ll i = 2; i * i < N; i++) {
    if (!Eratosthenes[i]) {
      for (ll j = 2; i * i * j * j <= N; j++)
        Eratosthenes[i * j] = 1;
    }
  }

  for (ll i : Eratosthenes) {
    if (!i) {
      int keep = 0;
      while (N % i == 0) {
        keep++;
        N /= i;
      }
      factor.emplace_back(keep);
    }
  }
  if (N > 1)
    factor.emplace_back(1);

  int ans = 0;
  for (int i : factor) {
    for (int j = 1; j <= i; j++) {
      ans++;
      i -= j;
    }
  }

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

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

int main() {
  long n;
  cin >> n;
  map<int, int> p;

  while (n % 2 == 0) {
    n /= 2;
    p[2] += 1;
  }
  int i = 3;
  while (n != 1 || n >= i) {
    if (pow(n, 0.5) < i) {
      p[n]++;
      break;
    }
    if (n % i == 0) {
      p[i]++;
      n /= i;
    } else {
      i += 2;
    }
  }

  int ans = 0;
  for (auto i : p) {
    int k = 1;
    while (i.second >= k) {
      ans++;
      i.second -= k;
      k++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long n;
  cin >> n;
  map<int, int> p;

  while (n % 2 == 0) {
    n /= 2;
    p[2] += 1;
  }
  int i = 3;
  while (n != 1 || n >= i) {
    if (n % i == 0) {
      p[i]++;
      n /= i;
    } else {
      i += 2;
    }
  }

  int ans = 0;
  for (auto i : p) {
    int k = 1;
    while (i.second >= k) {
      ans++;
      i.second -= k;
      k++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
  ll N;
  cin >> N;
  ll Nsave = N;
  ll n = (ll)sqrt(N);
  vector<int> cnt(n);
  for (int i = 2; i < n; i++) {
    while (N % i == 0) {
      cnt.at(i)++;
      N /= i;
    }
  }
  bool prime = true; // 最終的なNが素数かどうかを判定
  for (int i = 2; i < n; i++) {
    if (N % i == 0) {
      prime = false;
    }
  }
  ll ans;
  if (N == Nsave) {
    if (N == 1) {
      ans = 0;
    } else {
      ans = 1;
    }
  } else {
    if (prime && N != 1) {
      ans = 1;
    } else {
      ans = 0;
    }
    for (int i = 2; i < cnt.size(); i++) {
      int k = 1;
      while (cnt.at(i) - k >= 0) {
        ans++;
        cnt.at(i) -= k;
        k++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<int> cnt(N);
  ll j = 1;
  for (ll i = 2; i < 8000000; i++) {
    while (N % i == 0) {
      N /= i;
      cnt.at(j)++;
    }
    j++;
  }
  ll ans = 0;
  for (ll i = 0; i < cnt.size(); i++) {
    ll k = 1;
    while (cnt.at(i) - k >= 0) {
      cnt.at(i) -= k;
      k++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  long long N;
  cin >> N;
  auto pf = prime_factorize(N);
  long long res = 0;
  for (auto p : pf) {
    long long e = p.second;
    long long tmp = 0, cur = 1;
    while (e >= cur)
      e -= cur++, ++tmp;
    res += tmp;
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

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

vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (int p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      n /= p;
      ++num;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  long long n;
  cin >> n;
  auto a = prime_factorize(n);

  long long ans = 0;
  for (auto tp : a) {
    long long cnt = tp.second;
    long long temp = 0, cur = 1;
    while (cnt >= cur)
      cnt -= cur++, ++temp;
    ans += temp;
  }

  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll i = 2; i <= sqrt(n);
       i++) // factorization , this way only primes divides the N
  {
    if (n % i == 0) {
      ll cnt = 0, prev = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
        if (cnt > prev) {
          ans++;
          prev = cnt;
          cnt = 0;
        }
      }
    }
  }
  if (n > 1) // n itself is prime
    ans++;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define pb push_back
#define f(i, n) for (i = 0; i < n; i++)
#define F(i, a, b) for (i = a; a <= b; i++)
#define arr(a, n)                                                              \\
  for (i = 0; i < n; i++)                                                      \\
    cin >> a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a, a + n);
#define sr() sort(a, a + n, greater<ll>());
#define v() sort(v.begin(), v.end());
#define vr() sort(v.begin(), v.end(), greater<ll>());
#define mod 1000000007
#define fast()                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll a[10000000];
int main() {
  /*#ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/

  fast();
  // ll t;cin>>t;while(t--)
  {
    for (int i = 0; i < 10000000; i++) {
      a[i] = 1;
    }
    for (int i = 2; i <= sqrt(10000000); i++) {
      if (a[i]) {
        for (int j = i * i; j < 10000000; j += i) {
          a[j] = 0;
        }
      }
    }
    vi v;
    ll n, c = 0;
    cin >> n;
    for (ll i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        if (i == n / i)
          v.pb(i);
        else {
          v.pb(i);
          v.pb(n / i);
        }
      }
    }
    sort(v.begin(), v.end());

    ll val = v.size();
    for (ll i = 0; i < val; i++) {

      if (a[v[i]]) {

        ll temp = v[i];
        while (n % temp == 0) {
          n /= temp;
          c++;
          temp *= v[i];
        }
      }
    }

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

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

bool isprime(int64_t n) {
  if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;

  bool ans = true;
  int64_t check = 3;
  while (check * check <= n) {
    if (n % check == 0) {
      ans = false;
      return ans;
    }

    check += 2;
  }
  return ans;
}

int sankaku(int n) {
  int ans = 0;
  int sum = 1;
  int check = 1;
  while (n >= sum) {
    ans++;
    check++;
    sum += check;
  }

  return ans;
}

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

  int64_t n2 = n;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (isprime(n)) {
    cout << 1 << endl;
    return 0;
  }

  int64_t ma = 1;
  while (ma * ma < n)
    ma++;
  ma++;

  // bool prime[ma];
  bool *prime = (bool *)malloc(sizeof(bool) * ma);

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

  int64_t posi = 2;
  while (posi < ma) {
    if (prime[posi]) {
      int64_t move = posi * posi;
      while (move < ma) {
        prime[move] = false;
        move += posi;
      }
    }
    posi++;
  }

  // cout<<"B"<<endl;

  int ans = 0;
  for (int i = 2; i < ma; i++) {
    if (prime[i]) {
      int tmp = 0;
      while (n2 % i == 0) {
        n2 = n2 / i;
        tmp++;
      }
      ans += sankaku(tmp);

      if (n2 == 1)
        break;
    }
  }

  if (n2 >= ma)
    ans++;

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

bool isprime(int64_t n) {
  if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;

  bool ans = true;
  int64_t check = 3;
  while (check * check <= n) {
    if (n % check == 0) {
      ans = false;
      return ans;
    }

    check += 2;
  }
  return ans;
}

int sankaku(int n) {
  int ans = 0;
  int sum = 1;
  int check = 1;
  while (n >= sum) {
    ans++;
    check++;
    sum += check;
  }

  return ans;
}

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

  int64_t n2 = n;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (isprime(n)) {
    cout << 1 << endl;
    return 0;
  }

  int64_t ma = 1;
  while (ma * ma < n)
    ma++;
  ma += 2;

  // bool prime[ma];
  bool *prime = (bool *)malloc(sizeof(bool) * ma);

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

  int64_t posi = 2;
  while (posi < ma) {
    if (prime[posi]) {
      int64_t move = posi * posi;
      while (move < ma) {
        prime[move] = false;
        move += posi;
      }
    }
    posi++;
  }

  // cout<<"B"<<endl;

  int ans = 0;
  for (int i = 2; i * i <= n; i++) {
    if (prime[i]) {
      int tmp = 0;
      while (n2 % i == 0) {
        n2 = n2 / i;
        tmp++;
      }
      ans += sankaku(tmp);

      if (n2 == 1)
        break;
    }
  }

  if (n2 >= ma)
    ans++;

  cout << ans << endl;

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

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll, int>> factor(ll x) {
    vector<pair<ll, int>> res;
    for (int p : primes) {
      int y = 0;
      while (x % p == 0)
        x /= p, ++y;
      if (y != 0)
        res.emplace_back(p, y);
    }
    if (x != 1)
      res.emplace_back(x, 1);
    return res;
  }
};

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

  Sieve s(1000005);
  auto fs = s.factor(n);

  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 <iostream>
#include <math.h>

using namespace std;

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main() {
  long N;
  long result = 0;
  cin >> N;
  long a = N;

  for (int i = 2; i < N + 1; i++) {
    /* code */
    if (a % i == 0) {
      result++;
      a /= i;
      // cout << i << "," << N << endl;
    }
  }

  // cout << 4 % 4 << endl;
  cout << result << endl;
}