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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ret return 0
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int NUM = 2e5 + 5;
int main() {
  ios int num_tests = 1;
  // cin>>num_tests;
  while (num_tests-- > 0) {
    ll n;
    cin >> n;
    map<ll, ll> ma;
    int ans = 0;
    for (ll i = 2; i <= 1e7; i++) {
      int cnt = 0;
      if (n % i == 0) {
        while (n % i == 0) {
          n /= i;
          cnt++;
        }
      }
      if (cnt)
        ma[i] = cnt;
    }
    if (n != 1)
      ma[n] = 1;
    // for(auto x:ma) cout<<x.F<<" "<<x.S<<endl;
    for (auto x : ma) {
      int cnt = 0;
      int pow = 0;
      for (int i = 1;; i++) {
        pow += i;
        if (pow <= x.S)
          cnt++;
        else
          break;
      }
      ans += cnt;
    }
    cout << ans;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ret return 0
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int NUM = 2e5 + 5;
bool isprime(ll n) {
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
int main() {
  ios int num_tests = 1;
  // cin>>num_tests;
  while (num_tests-- > 0) {
    ll n;
    cin >> n;
    if (isprime(n)) {
      cout << 1;
      ret;
    }
    map<ll, ll> ma;
    int ans = 0;
    for (ll i = 2; i <= 1e6; i++) {
      int cnt = 0;
      if (n % i == 0) {
        ll div = i;
        // cout<<div<<endl;
        while (n % div == 0) {
          n /= i;
          cnt++;
        }
      }
      if (cnt)
        ma[i] = cnt;
    }
    if (n != 1)
      ma[n] = 1;
    // for(auto x:ma) cout<<x.F<<" "<<x.S<<endl;
    for (auto x : ma) {
      int cnt = 0;
      int pow = 0;
      for (int i = 1;; i++) {
        pow += i;
        if (pow <= x.S)
          cnt++;
        else
          break;
      }
      ans += cnt;
    }
    cout << ans;
  }
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define fl(i, n) for (i = 0; i < n; i++)
#define fld(i, a, b) for (i = a; i > b; i--)
#define fli(i, a, n) for (i = a; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define speedup ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;
ll a[10000001];
void sieve() {
  ll i, j;
  fli(i, 2, 10000001) {
    if (a[i] == 0) {
      for (j = i * 2; j < 10000001; j += i) {
        a[j]++;
      }
    }
  }
}
void comp() {
  ll i, j, k, n, m;
  cin >> n;
  sieve();
  vector<ll> primes;
  fli(i, 2, 1000001) {
    if (!a[i])
      primes.pb(i);
  }
  map<ll, ll> m1;
  fl(i, primes.size()) {
    ll count1 = 0;
    while (n % primes[i] == 0) {
      n /= primes[i];
      count1 += 1;
    }
    if (count1 > 0)
      m1[primes[i]] = count1;
    if (n == 1)
      break;
  }
  if (n > 1)
    m1[n] = 1;
  ll ans = 0;
  map<ll, ll>::iterator it = m1.begin();
  while (it != m1.end()) {
    ll temp1 = 0;
    fli(i, 1, 40) {
      ll temp = (i * (i + 1)) / 2;
      if (temp <= it->second) {
        temp1 = i;
      } else {
        break;
      }
    }
    ans += temp1;
    it++;
  }
  cout << ans << "\\n";
}

int main() {
  speedup;
  ll i = 0, t;
  t = 1;
  // cin>>t;
  while (t--) {
    comp();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define fl(i, n) for (i = 0; i < n; i++)
#define fld(i, a, b) for (i = a; i > b; i--)
#define fli(i, a, n) for (i = a; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define speedup ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;
ll a[1000001];
void sieve() {
  ll i, j;
  fli(i, 2, 1000001) {
    if (a[i] == 0) {
      for (j = i * 2; j < 1000001; j += i) {
        a[j]++;
      }
    }
  }
}
void comp() {
  ll i, j, k, n, m;
  cin >> n;
  ll temp = sqrt(n) + 1;
  sieve();
  if (n == 1) {
    cout << 0;
    return;
  }
  priority_queue<ll, vector<ll>, greater<ll>> q1;
  fli(i, 2, temp) {
    if (n % i == 0) {
      if (n / i != i) {
        if (a[i] <= 1)
          q1.push(i);
        if (a[n / i] <= 1)
          q1.push(n / i);
      } else {
        if (a[i] <= 1)
          q1.push(i);
      }
    }
  }
  ll ans = 0;
  while (!q1.empty()) {
    ll temp = q1.top();
    q1.pop();
    n /= temp;
    ans++;
    if (n == 1)
      break;
  }
  ans = max(1ll, ans);
  cout << ans << "\\n";
}

int main() {
  speedup;
  ll i = 0, t;
  t = 1;
  // cin>>t;
  while (t--) {
    comp();
  }
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int ret(int n) {
  int i = sqrt(n);
  while (i * (i + 1) <= 2 * n)
    i++;
  if (i * (i + 1) > 2 * n)
    i--;
  return i;
}
int main() {
  long long n;
  cin >> n;
  int ans = 0;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      ans += ret(cnt);
    }
  }
  if (n > 1)
    ans += 1;
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int ret(int n) {
  int i = sqrt(n);
  while (i * (i + 1) <= 2 * n)
    i++;
  if (i * (i + 1) > 2 * n)
    i--;
  return i;
}
int main() {
  long long n;
  cin >> n;
  int ans = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      ans += ret(cnt);
    }
  }
  if (n > 1)
    ans += 1;
  cout << ans << "\\n";
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

/* Start coding only after you have clear idea.*/
#pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 1e6 + 11;
#define inf 2000000007
#define mod 1000000007
#define IosF ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int prime[N / 3];
int miniFactor[N];
int primepos = 0;
void euler() {
  int tmp;
  for (int i = 2; i < N; i++) {
    if (!miniFactor[i])
      prime[primepos++] = i, miniFactor[i] = i;
    for (int j = 0; (tmp = i * prime[j]) < N && j < primepos; j++) {
      miniFactor[tmp] = prime[j];
      if (!(i % prime[j]))
        break;
    }
  }
}

vector<ll> Q;
int main() {
  IosF;
  euler();
  ll n, k;
  cin >> n;
  for (int i = 0; i < primepos; ++i) {
    k = 1ll * prime[i];
    while (k <= n) {
      Q.push_back(k);
      k *= 1ll * prime[i];
    }
  }
  sort(Q.begin(), Q.end());
  int len = Q.size(), res = 0;
  //    cout << len << endl;
  k = n;
  for (int i = 0; i < len; ++i) {
    if (k % Q[i])
      continue;
    if (k < Q[i])
      break;
    k /= Q[i];
    ++res;
  }
  for (int i = 0; i < primepos; ++i) {
    while (!(n % prime[i]))
      n /= prime[i];
  }
  if (n > 1)
    ++res;
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:

/* Start coding only after you have clear idea.*/
#pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5 + 11;
#define inf 2000000007
#define mod 1000000007
#define IosF ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

vector<ll> Q;
int main() {
  IosF;
  ll n, k;
  cin >> n;
  unordered_map<ll, bool> mymap;
  for (ll i = 2; i * i <= n; ++i) {
    k = i;
    while (k <= n) {
      if (mymap[k])
        break;
      mymap[k] = true;
      Q.push_back(k);
      k *= i;
    }
  }

  int res = 0;
  for (int i = 0; i < Q.size(); ++i) {
    if (n % Q[i])
      continue;
    n /= Q[i];
    ++res;
  }
  if (n > Q[Q.size() - 1])
    ++res;
  cout << res << endl;

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

#include <bits/stdc++.h>

using namespace std;

long long n;

int solve(int x) {
  int s = 0, i = 0;
  while (s <= x) {
    i++;
    s += i;
  }
  return i - 1;
}

void process() {
  int kq = 0;
  int dem = 0;
  while (n % 2 == 0) {
    dem++;
    n /= 2;
  }
  kq += solve(dem);
  for (long long i = 3; i * i <= n; i += 2) {
    dem = 0;
    while (n % i == 0) {
      dem++;
      n /= i;
    }
    kq += solve(dem);
  }
  if (n > 2)
    kq++;
  cout << kq;
}

int main() {
  scanf("%lld", &n);
  process();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long n;

int solve(int x) {
  int s = 0, i = 0;
  while (s <= x) {
    i++;
    s += i;
  }
  return i - 1;
}

void process() {
  int kq = 0;
  int dem = 0;
  while (n % 2 == 0) {
    dem++;
    n /= 2;
  }
  kq += solve(dem);
  for (int i = 3; i * i <= n; i += 2) {
    dem = 0;
    while (n % i == 0) {
      dem++;
      n /= i;
    }
    kq += solve(dem);
  }
  if (n > 2)
    kq++;
  cout << kq;
}

int main() {
  scanf("%lld", &n);
  process();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll pow(ll x, ll y) {
  if (y == 0) {
    return 1;
  }
  if (y == 1) {
    return x;
  }
  if (y % 2 == 0) {
    return pow(x, y / 2) * pow(x, y / 2);
  } else {
    return x * pow(x, y / 2) * pow(x, y / 2);
  }
}
struct Sieve {
  int n;
  vector<int> mindivnum, primes;
  Sieve(int n = 1) : n(n), mindivnum(n + 1) {
    mindivnum[0] = mindivnum[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (mindivnum[i])
        continue;
      primes.push_back(i);
      mindivnum[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!mindivnum[j])
          mindivnum[j] = i;
      }
    }
  }
  bool isPrime(int x) { return mindivnum[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(mindivnum[x]);
      x /= mindivnum[x];
    }
    return res;
  }
  vector<pair<int, int>> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<pair<int, int>> res(1, pair<int, int>(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(1000000);
  auto fs = s.factor(n);
  int ans = 0;
  for (auto p : fs) {
    int a = p.second;
    int b = 1;
    while (a >= b) {
      a -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int cnt = 0;
  vector<int> prime(120000000);
  rep(i, prime.size()) { prime[i] = 1; }
  for (int i = 2; i < sqrt(n); i++) {
    if (n % i == 0) {
      for (int j = 2; i * j < sqrt(n); j++) {
        prime[i * j] = 0;
      }
    }
  }
  int size = prime.size();
  for (int i = 2; i < size; i++) {
    if (prime[i] == 1) {
      for (int j = 1; j < 10000000; j++) {
        int a = pow(i, j);
        if (n % a == 0) {
          // cout << a << endl;
          cnt++;
          n /= a;
        } else {
          break;
        }
      }
    }
  }
  if (cnt == 0) {
    cout << 1 << endl;
    return 0;
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

// 何bitたっているか
int func2(ll x) {
  int hiku = 1;
  int cnt = 0;
  while (x - hiku >= 0) {
    x -= hiku;
    cnt++;
    hiku++;
  }
  return cnt;
}

// 素因数分解
ll func(ll n) {
  ll x = 2;
  ll cnt = 0;
  ll sum = 0;
  bool isPrime = false;
  while (n >= x) {
    if (n % x == 0) {
      n /= x;
      cnt++;
    } else {
      int val = func2(cnt);
      sum += val;
      cnt = 0;
      x++;
    }
  }
  if (cnt > 0) {
    int val = func2(cnt);
    sum += val;
  }
  return sum;
}

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

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

    // その結果を push
    res.push_back({a, ex});
  }

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

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

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

  vector<pair<long long, long long>> vec = prime_factorize(n);

  ll sum = 0;
  for (pair<long long, long long> val : vec) {
    sum += func2(val.second);
  }
  // cout << func(n) << endl;
  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

// 何bitたっているか
int func2(ll x) {
  int hiku = 1;
  int cnt = 0;
  while (true) {
    x -= hiku;
    if (x < 0) {
      break;
    }
    cnt++;
    hiku++;
  }
  return cnt;
}

// 素因数分解
ll func(ll n) {
  ll x = 2;
  ll cnt = 0;
  ll sum = 0;
  while (n >= x) {
    if (n % x == 0) {
      n /= x;
      cnt++;
      // printf("get %lld %lld", x, n);
    } else {
      int val = func2(cnt);
      // printf(": %d %d \\n", cnt, val);
      sum += val;
      cnt = 0;
      x++;
    }
  }
  if (cnt > 0) {
    int val = func2(cnt);
    // printf(" %d \\n", cnt, val);
    sum += val;
  }
  return sum;
}

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

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

  cout << func(n) << endl;

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

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

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      res.back().second++;
      n /= i;
    }
  }
  if (n > 1) {
    res.emplace_back(n, 1);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto v = factorize(n);
  ll ans = 0;
  rep(i, v.size()) {
    ll count = 0;
    while (1) {
      if ((count + 1) * count / 2 > v[i].second) {
        count--;
        break;
      }
      count++;
    }
    ans += count;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      res.back().second++;
      n /= i;
    }
  }
  if (n > 1) {
    res.emplace_back(n, 1);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto v = factorize(n);
  ll ans = 0;
  rep(i, v.size()) {
    int count = 0;
    while (1) {
      if ((count + 1) * count / 2 > v[i].second) {
        count--;
        break;
      }
      count++;
    }
    ans += count;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

#include <math.h>

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 long N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (IsPrime(N)) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 0;
  double root = sqrt(N);
  for (int i = 2; i <= root; i++) {
    int cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
      long long z = i * i;
      while (N % z == 0) {
        N /= z;
        z *= i;
        cnt++;
      }
      for (int j = 0; j < cnt; j++) {
        z /= i;
        if (N % z == 0)
          N /= z;
      }
    }
    ans += cnt;
  }
  if (N != 1)
    ans++;

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

#include <math.h>

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 long N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (IsPrime(N)) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 0;
  for (int i = 2; i <= N; i++) {
    if (IsPrime(i)) {
      if (N % i == 0) {
        N /= i;
        ans++;
        int z = i * i;
        while (N % z == 0) {
          N /= z;
          z *= i;
          ans++;
        }
        while (N % i == 0)
          N /= i;
      }
    }
  }

  cout << ans << 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++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep1(i, n) for (int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  map<ll, ll> m;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      m[i]++;
    }
  }
  if (n > 1)
    m[n]++;

  vector<pll> lim;
  for (ll i = 1; i < 100; i++)
    lim.push_back({i * (i + 1) / 2, i});

  ll result = 0;
  for (auto c : m) {
    ll count = c.second;
    auto it = lower_bound(lim.begin(), lim.end(), make_pair(count, -1LL));
    // cout<<(*it).first<<' '<<(*it).second<<' '<<count<<endl;
    if ((*it).first > count)
      it--;
    result += (*it).second;
  }

  cout << result << endl;

  //  for(auto c:m)cout<<c.first<<' '<<c.second<<endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep1(i, n) for (int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  map<ll, ll> m;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      m[i]++;
    }
  }
  if (n > 1)
    m[n]++;

  vector<pll> lim;
  for (ll i = 1; i < 1000; i++)
    lim.push_back({i * (i + 1) / 2, i});

  ll result = 0;
  for (auto c : m) {
    ll count = c.second;
    auto it = lower_bound(lim.begin(), lim.end(), make_pair(count, -1LL));
    // cout<<(*it).first<<' '<<(*it).second<<' '<<count<<endl;
    if ((*it).first > count)
      it--;
    result += (*it).second;
  }

  cout << result << endl;

  //  for(auto c:m)cout<<c.first<<' '<<c.second<<endl;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i * i < n; ++i)
    if (primes[i])
      for (int j = i * i; j < n; j += i)
        primes[j] = 0;
  return primes;
}

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

  ll n;

  cin >> n;

  vector<int> primes = sieve_of_eratosthenes(static_cast<int>(sqrt(n + 1)));
  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());

  vector<ll> q;
  int i = 0;
  bool next = false;

  while (n != 1) {
    if (i == primes.size()) {
      q.emplace_back(1);
      break;
    }
    if (n % primes.at(i) == 0) {
      if (!next) {
        q.emplace_back(1);
        n /= primes.at(i);
        next = true;
      } else {
        q.back()++;
        n /= primes.at(i);
      }
    } else {
      ++i;
      next = false;
    }
  }

  int ans = 0;

  for (int i : q) {
    for (int j = 1; true; ++j) {
      i -= j;
      if (i >= 0)
        ++ans;
      else
        break;
    }
  }

  printf("%d\\n", ans);

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744072887055744) >= this->size() (which is 2)


Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i * i < n; ++i)
    if (primes[i])
      for (int j = i * i; j < n; j += i)
        primes[j] = 0;
  return primes;
}

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

  ll n;

  cin >> n;

  vector<int> primes = sieve_of_eratosthenes(sqrt(n + 1));
  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());

  vector<ll> q;
  int i;
  bool next;

  while (n != 1) {
    if (i == primes.size()) {
      q.emplace_back(1);
      break;
    }
    if (n % primes.at(i) == 0) {
      if (!next) {
        q.emplace_back(1);
        n /= primes.at(i);
        next = true;
      } else {
        q.back()++;
        n /= primes.at(i);
      }
    } else {
      ++i;
      next = false;
    }
  }

  int ans = 0;

  for (int i : q) {
    for (int j = 1; true; ++j) {
      i -= j;
      if (i >= 0)
        ++ans;
      else
        break;
    }
  }

  printf("%d\\n", ans);

  return 0;
}