alexjercan/bugnet huggingface dataset:
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef long long ll;
#define dump(x) cerr << #x << "=" << x << endl
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll cnt = 0;
  vector<pair<ll, int>> f;
  for (int i = 2; i <= (ll)sqrt(n); i++) {
    if (n % i == 0) {
      ll tmp = 0;
      while (n % i == 0) {
        n /= i;
        tmp++;
      }

      f.push_back(make_pair(i, tmp));
    }
  }

  if (n != 1)
    f.emplace_back(n, 1);
  for (auto p : f) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++cnt;
    }
  }

  cout << cnt << endl;
  return 0;
}


Error: 0
sqrt(n)=4.89898


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef long long ll;
#define dump(x) cerr << #x << "=" << x << endl
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  vector<bool> z(100000000, false);

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

  dump(sqrt(n));
  for (ll i = 2; i <= (ll)sqrt(n); i++) {
    if ((n % i) == 0) {
      break;
    } else {
      if (i == (ll)sqrt(n)) {
        cout << 1 << endl;
        return 0;
      }
    }
  }

  ll tmp = n;
  ll cnt = 0;
  for (ll i = 2; i <= (ll)sqrt(n); i++) {
    if (tmp % i == 0) {
      if (i <= 4) {
        cnt++;
        tmp /= i;
        z.at(i) = true;
        continue;
      }

      for (ll j = 2; j <= (ll)sqrt(i); j++) {
        if (i % j == 0) {
          ll tmp2 = j;
          bool ok = false;

          while (i != tmp2) {
            if (i < tmp2) {
              break;
            }
            tmp2 *= j;
          }

          if (i == tmp2) {
            ok = true;
          }

          if (ok) {
            cnt++;
            tmp /= i;
            z.at(i) = true;
          }
          break;
        } else {
          if (j == (ll)sqrt(i)) {
            cnt++;
            tmp /= i;
            z.at(i) = true;
          }
        }
      }
    }

    if (tmp <= 1) {
      break;
    }
  }

  if (z.at(tmp)) {
    cout << cnt << endl;
    return 0;
  }

  for (ll i = 2; i <= sqrt(tmp); i++) {
    if ((tmp % i) == 0) {
      break;
    } else {
      if (i == (ll)sqrt(tmp)) {
        cnt++;
      }
    }
  }

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

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
vector<long> divisor;
vector<long> counter;

void sosu(long long x) {
  long long xq = round(sqrtl(x)) + 1;
  long count = 0;
  long long xx = x;
  bool flag = false;
  for (auto i = 2; i <= xq; i++) {
    count = 0;
    // cout << i << ": ";
    while (xx % i == 0) {
      xx = xx / i;
      count++;
      if (xx == 1) {
        flag = true;
        break;
      }
    }
    if (count != 0) {
      divisor.push_back(i);
      counter.push_back(count);
      xq = round(sqrt(xx));
    }
  }
  if ((!flag) && (xx > 1)) {
    divisor.push_back(xx);
    counter.push_back(1);
  }
}
int cc(long x) {
  int count = 0;
  for (auto i = 1; i <= x; i++) {
    if (i <= x) {
      count++;
      x -= i;
    }
  }
  return count;
}

int main() {
  long long n, z;
  cin >> n;
  long count = 0, sum = 0;
  sosu(n);
  /*
  cout << "(divisor, counter)";
  for(auto i=0;i<divisor.size();i++){
      cout << "(" << divisor.at(i) << "," << counter.at(i) << "), ";
  }
  */
  if (divisor.size() == 0) {
    cout << ((n == 1) ? 0 : 1) << endl;
    return 0;
  } else {
    for (auto i = 0; i < divisor.size(); i++) {
      sum += cc(counter.at(i));
    }
  }
  cout << sum << endl;
  //*/
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
vector<long> divisor;
vector<long> counter;

void sosu(long long x) {
  long long xq = round(sqrtl(x)) + 1;
  long count = 0;
  long long xx = x;
  for (auto i = 2; i <= xq; i++) {
    count = 0;
    // cout << i << ": ";
    while (xx % i == 0) {
      xx = xx / i;
      count++;
    }
    if (count != 0) {
      divisor.push_back(i);
      counter.push_back(count);
      xq = xx;
    }
  }
}
int cc(long x) {
  int count = 0;
  for (auto i = 1; i <= x; i++) {
    if (i <= x) {
      count++;
      x -= i;
    }
  }
  return count;
}

int main() {
  long long n, z;
  cin >> n;
  long count = 0, sum = 0;
  sosu(n);
  /*
  cout << "(divisor, counter)";
  for(auto i=0;i<divisor.size();i++){
      cout << "(" << divisor.at(i) << "," << counter.at(i) << "), ";
  }
  */
  if (divisor.size() == 0) {
    cout << ((n == 1) ? 0 : 1) << endl;
    return 0;
  } else {
    for (auto i = 0; i < divisor.size(); i++) {
      sum += cc(counter.at(i));
    }
  }
  cout << sum << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v) {
  for (int i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  lli n;
  cin >> n;
  lli nc = n;
  map<lli, lli> prime;
  lli i = 2;
  lli ans = 0;
  while (nc != 1) {
    if (i * i > n) {
      prime[n] = 1;
      break;
    }
    if (nc % i == 0) {
      lli count = 0;
      while (nc % i == 0) {
        nc /= i;
        count++;
      }
      prime[i] = count;
    }
    i++;
  }
  for (auto v : prime) {
    lli count = 1, now = 0;
    lli per = 0;
    while (v.second > now) {
      now += count;
      per++;
      count++;
      if (v.second < now) {
        per -= 1;
      }
    }
    ans += per;
  }
  out(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v) {
  for (int i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  lli n;
  cin >> n;
  lli nc = n;
  map<lli, lli> prime;
  lli i = 2;
  lli ans = 0;
  while (nc != 1) {
    if (nc % i == 0) {
      lli count = 0;
      while (nc % i == 0) {
        nc /= i;
        count++;
      }
      prime[i] = count;
    }
    i++;
  }
  for (auto v : prime) {
    lli count = 1, now = 0;
    lli per = 0;
    while (v.second > now) {
      now += count;
      per++;
      count++;
      if (v.second < now) {
        per -= 1;
      }
    }
    ans += per;
  }
  out(ans);
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

// c++ テンプレ
#include <bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef unsigned long LInt;
typedef long double ld;

#define inf 1e18
constexpr long long INFLL = 1e18;
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

map<llint, llint> mp;
bool prime[1000005];

void solve() {
  llint n;
  cin >> n;

  for (int i = 2; i < 1000005; i++) {
    if (prime[i])
      continue;
    for (int j = 2 * i; j < 1000005; j += i)
      prime[j] = true;
  }

  for (int i = 2; i < 1000005; i++) {
    if (prime[i])
      continue;
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n > 1)
    mp[n]++;
  llint ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    for (int i = 1;; i++) {
      if (it->second >= i) {
        ans++;
        it->second -= i;
      } else
        break;
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Error: 0

Fixed submission:

// c++ テンプレ
#include <bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef unsigned long LInt;
typedef long double ld;

#define inf 1e18
constexpr long long INFLL = 1e18;
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

map<llint, llint> mp;
bool prime[1000005];

void solve() {
  llint n;
  cin >> n;

  for (int i = 2; i < 1000005; i++) {
    if (prime[i])
      continue;
    for (int j = 2 * i; j < 1000005; j += i)
      prime[j] = true;
  }

  for (int i = 2; i < n; i++) {
    if (prime[i])
      continue;
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n > 1)
    mp[n]++;
  llint ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    for (int i = 1;; i++) {
      if (it->second >= i) {
        ans++;
        it->second -= i;
      } else
        break;
    }
  }
  cout << ans << endl;
}

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

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

int main() {
  long long n;
  int cnt = 0, l;
  cin >> n;
  vector<int> a(1000010, 0);

  for (int i = 2; i < 1000010; i++) {
    while (n % i == 0) {
      a.at(i)++;
      n = n / i;
    }
  }
  if (n >= 1000010)
    cnt++;
  for (int i = 0; i < 1000010; i++) {
    if (a.at(i) == 0)
      continue;
    else {
      l = 1;
      while (a.at(i) >= 0) {
        a.at(i) -= l;
        cnt++;
        l++;
      }
      cnt--;
    }
  }
  cout << cnt << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long n;
  int cnt = 0, l;
  cin >> n;
  vector<int> a(n, 0);

  for (int i = 2; i < 1000000 + 10; i++) {
    while (n % i == 0) {
      a.at(i)++;
      n = n / i;
    }
  }
  for (int i = 0; i < a.size(); i++) {
    if (a.at(i) == 0)
      continue;
    else {
      l = 1;
      while (a.at(i) >= 0) {
        a.at(i) -= l;
        cnt++;
        l++;
      }
      cnt--;
    }
  }
  cout << cnt << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

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

int prime_factrization(ll n) {
  vector<int> prime_num(int(sqrt(n)) + 1);
  int ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_num[i]++;
      n /= i;
    }
    int num = 1;
    while (prime_num[i] >= num) {
      prime_num[i] -= num;
      num++;
      ans++;
    }
  }
  if (n != 1)
    ans++;
  return ans;
}

int main() {
  ll N;
  cin >> N;
  int ans = prime_factrization(N);

  if (N != 1 && ans == 0)
    cout << 1 << endl;
  else
    cout << ans << endl;
}

Error: 0

Fixed submission:

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

int prime_factrization(ll n) {
  vector<int> prime_num(int(sqrt(n)) + 1);
  int ans = 0;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_num[i]++;
      n /= i;
    }
    int num = 1;
    while (prime_num[i] >= num) {
      prime_num[i] -= num;
      num++;
      ans++;
    }
  }
  if (n != 1)
    ans++;
  return ans;
}

int main() {
  ll N;
  cin >> N;
  int ans = prime_factrization(N);

  if (N != 1 && ans == 0)
    cout << 1 << endl;
  else
    cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
template <class A, class B> inline A max(A a, B b) { return (a > b ? a : b); }
template <class A, class B> inline A min(A a, B b) { return (a < b ? a : b); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
lol n, m, k, r;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  lol ans = 0;
  int p = -1;
  lol u = n;
  vector<int> se;
  for (lol i = 2; i * i <= u; i++) {
    if (n % i == 0) {
      n /= i;
      se.emplace_back(1);
      p++;
    }
    while (n % i == 0) {
      n /= i;
      se[p]++;
    }
  }
  if (n != 1)
    ans++;
  for (int i = 0; i <= p; i++) {
    int sum = 1;
    while (se[i] >= sum) {
      se[i] -= sum;
      sum++;
      ans++;
    }
  }
  cout << ans << '\\n';
  return (0);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
template <class A, class B> inline A max(A a, B b) { return (a > b ? a : b); }
template <class A, class B> inline A min(A a, B b) { return (a < b ? a : b); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
lol n, m, k, r;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  lol ans = 0;
  int p = -1;
  vector<int> se;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      n /= i;
      se.emplace_back(1);
      p++;
    }
    while (n % i == 0) {
      n /= i;
      se[p]++;
    }
  }
  if (n != 1)
    ans++;
  for (auto &&o : se) {
    int sum = 1;
    while (o >= sum) {
      o -= sum;
      sum++;
      ans++;
    }
  }
  cout << ans << '\\n';
  return (0);
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int maxn = 1e7 + 10;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  ll n;
  cin >> n;
  vii haha;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      ll x = 0;
      while (n % i == 0) {
        ++x;
        n /= i;
      }
      haha.pb({i, x});
    }
  }
  if (n != 1)
    haha.pb({n, 1});
  ll ans = 0;
  for (int i = 0; i < haha.size(); ++i) {
    for (int j = 1; j <= 300; ++j) {
      ++ans;
      if (haha[i].ss - j > j) {
        haha[i].ss -= j;
      } else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int maxn = 1e9 + 10;

vector<bool> sieve(maxn, true);
vector<ll> primes;

bool isprime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; i * i <= x; ++i) {
    if (x % i == 0)
      return false;
  }
  return true;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  ll n;
  cin >> n;
  if (isprime(n)) {
    cout << 1 << endl;
    return 0;
  }
  sieve[1] = sieve[0] = false;
  for (int i = 2; i < maxn; ++i) {
    if (sieve[i]) {
      primes.pb(i);
      for (int j = i + i; j < maxn; j += i)
        sieve[j] = false;
    }
  }
  map<int, int> mp;
  int i = 0;
  ll ans = 0;
  while (n > 1 && i < primes.size()) {
    while (n % primes[i] == 0) {
      n /= primes[i];
      ++ans;
      if (primes[i] * primes[i] < primes[i])
        break;
      primes[i] *= primes[i];
    }
    ++i;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#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 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() {
  long n;
  cin >> n;

  int count = 0;

  auto P = prime_factorize(n);

  for (auto i : P) {
    int ex = 1;
    while (true) {
      if (i.second - ex >= 0) {
        i.second -= ex;
        ex++;
        count++;
      } else {
        break;
      }
    }
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

vector<long> Eratosthenes(const long N) {
  vector<bool> is_prime(N + 1);

  for (long i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  vector<long> P;

  for (long i = 2; i * i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

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

  int count = 0;

  vector<long> P = Eratosthenes(n);

  int i = 0;

  while (true) {
    if (n == 1) {
      break;
    }
    int prime = P[i];
    int e = 1;
    while (n % prime == 0) {
      bool flg = true;
      for (int j = 1; j <= e; j++) {
        if (n % prime == 0) {
          n = n / prime;
        } else {
          flg = false;
        }
      }
      if (flg == true) {
        count++;
        e++;
      }
    }
    i++;
  }
  cout << count << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

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

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

  int ans = 0;
  auto factors = prime_factorize(n);
  for (auto f : factors) {
    int c = f.second;
    int i = 1;
    while (i <= c) {
      c -= i;
      ++i;
      ++ans;
    }
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

map<ll, int> prime_factorize(ll m) {
  map<ll, int> ret;
  for (int i = 2; i * i <= m; ++i) {
    while (m % i == 0) {
      if (ret.count(i) == 0)
        ret[i] = 1;
      else
        ++ret[i];
      m /= i;
    }
  }
  if (m != 1)
    ret[m] = 1;
  return ret;
}

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

  int ans = 0;
  auto factors = prime_factorize(n);
  for (auto f : factors) {
    int c = f.second;
    for (int i = 1; i <= c; ++i) {
      c -= i;
      if (c < 0)
        break;
      ++ans;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
// Copyright (c) 2020 0214sh7
// https://github.com/0214sh7/library/
vector<long long> prime_factorization(long long N) {
  vector<long long> R;
  if (N < 2)
    return R;
  for (long long i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      R.push_back(i);
      N /= i;
    }
  }
  if (N != 1) {
    R.push_back(N);
  }
  return R;
}

int main() {

  long long A;
  cin >> A;
  if (A == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> R;
  R = prime_factorization(A);
  sort(R.begin(), R.end());
  int X = R.size();
  int csr = 0;
  int Total = 0;
  long long pr = R.at(0);
  while (csr != X) {
    int cnt = lower_bound(R.begin(), R.end(), pr + 1) - R.begin() - csr;
    csr = lower_bound(R.begin(), R.end(), pr + 1) - R.begin();
    if (csr != X)
      pr = R.at(csr);

    // cout << cnt << endl;

    int j = 1;
    while (j <= cnt) {
      cnt -= j;
      j++;
    }

    Total += j - 1;
  }

  cout << Total << endl;
}

Error: TLE

Fixed submission:

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

// 素因数分解
// Copyright (c) 2020 0214sh7
// https://github.com/0214sh7/library/
vector<long long> prime_factorization(long long N) {
  vector<long long> R;
  if (N < 2)
    return R;
  for (int i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      R.push_back(i);
      N /= i;
    }
  }
  if (N != 1) {
    R.push_back(N);
  }
  return R;
}

int main() {

  long long A;
  cin >> A;
  if (A == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> R;
  R = prime_factorization(A);
  sort(R.begin(), R.end());
  int X = R.size();
  int csr = 0;
  int Total = 0;
  long long pr = R.at(0);
  while (csr != X) {
    int cnt = lower_bound(R.begin(), R.end(), pr + 1) - R.begin() - csr;
    csr = lower_bound(R.begin(), R.end(), pr + 1) - R.begin();
    if (csr != X)
      pr = R.at(csr);

    // cout << cnt << endl;

    int j = 1;
    while (j <= cnt) {
      cnt -= j;
      j++;
    }

    Total += j - 1;
  }

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

#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

  map<long long, int> m;
  for (long long i = 2; i * i <= N; i += 1) {
    while (N % i == 0) {
      if (m.count(i) == 0)
        m.insert(make_pair(i, 1));
      else
        ++m[i];
      N /= i;
    }
  }
  if (N != 1 && m.count(N) == 0)
    m.insert(make_pair(N, 1));

  int cnt = 0;
  for (auto x : m) {
    int d = 1;
    while (x.second - d >= 0) {
      x.second -= d;
      ++d;
      ++cnt;
    }
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

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

  int cnt = 0;
  set<int> used, notPrime;
  for (int i = 2; N != 1; ++i) {
    // 素数じゃなければスキップ
    if (notPrime.count(i) == 1)
      continue;

    // 約数の登録
    for (int j = 1; (int)(pow(i, j) + 0.5) <= N; ++j) {
      int p = pow(i, j) + 0.5;
      notPrime.insert(p);
      if (used.count(p) == 1)
        continue;

      if (N % p == 0) {
        N /= p;
        used.insert(p);
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
}