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

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

template <typename T> vector<pair<T, T>> FACTORIZATION(T x) {
  vector<pair<T, T>> ans;
  for (T i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      T count = 0;
      while (x % i == 0) {
        count++;
        x /= i;
      }
      ans.push_back(make_pair(count, i));
    }
  }
  if (x != 1)
    ans.push_back(make_pair(1, x));
  return ans;
}

int main(void) {
  int64_t N;
  int64_t remains = 0;
  int loopcnt = 0;
  int ans = 0;
  cin >> N;

  // z = p^e zは2以上(eが正の整数）

  // 素因数分解して最も大きい指数の基数を取ってくる
  // ソートしやすいように後ろが基数
  vector<pair<int64_t, int64_t>> lst = FACTORIZATION(N);
  sort(lst.begin(), lst.end());
  //    unordered_set<int64_t> st;

  for (int i = 0; i < lst.size(); i++) {
    remains += lst[i].first;
  }

  // 最初は１個ずつ使っていって、
  for (int i = 0; i < lst.size(); i++) {
    //        st.insert(lst[i].second);
    N /= lst[i].second;
    lst[i].first--;
    remains--;
  }
  ans = lst.size();

  // setにあったら２個以上連続を割る
  if (remains) {
    for (int i = lst.size() - 1; i >= 0; i--) {
      loopcnt = 2;
      while (lst[i].first >= loopcnt) {
        lst[i].first -= loopcnt;
        N /= pow(lst[i].second, loopcnt);
        //                st.insert(make_pair(lst[i].second, loopcnt));
        ans++;
        loopcnt++;
      }
    }
  }

  // ここまでで大分小さくなっているはずなのであとは総当り
  // 組み合わせは考慮不要なのでここまででOKのはず
  ///    vector<pair<int64_t,int64_t>> lst2 = FACTORIZATION(N);
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

template <typename T> vector<pair<T, T>> FACTORIZATION(T x) {
  vector<pair<T, T>> ans;
  for (T i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      T count = 0;
      while (x % i == 0) {
        count++;
        x /= i;
      }
      ans.push_back(make_pair(count, i));
    }
  }
  if (x != 1)
    ans.push_back(make_pair(1, x));
  return ans;
}

struct phash {
  inline size_t operator()(const pair<int64_t, int64_t> &p) const {
    const auto h1 = hash<int>()(p.first);
    const auto h2 = hash<int>()(p.second);
    return h1 ^ (h2 << 1);
  }
};

int main(void) {
  int64_t N;
  int64_t remains = 0;
  int loopcnt = 0;
  int ans = 0;
  cin >> N;

  // z = p^e zは2以上(eが正の整数）

  // 素因数分解して最も大きい指数の基数を取ってくる
  // ソートしやすいように後ろが基数
  vector<pair<int64_t, int64_t>> lst = FACTORIZATION(N);
  sort(lst.begin(), lst.end());
  unordered_set<pair<int64_t, int64_t>, phash> st;

  for (int i = 0; i < lst.size(); i++) {
    remains += lst[i].first;
  }

  // 最初は１個ずつ使っていって、
  for (int i = 0; i < lst.size(); i++) {
    st.insert(make_pair(lst[i].second, 1));
    lst[i].first--;
    remains--;
  }
  ans = lst.size();

  // setにあったら２個または後ろのペアで
  //  ここわからん
  while (remains) {
    for (int i = lst.size() - 1; i >= 0; i--) {
      loopcnt = 2;
      while (lst[i].first >= loopcnt) {
        lst[i].first -= loopcnt;
        ans++;
        loopcnt++;
      }
    }
  }
  cout << ans + (remains / 2) << 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++)

bool is_prime(int n) {
  int x = 1;
  if (n < 2)
    return false;
  else if (n % 2 == 0)
    x = 2;
  else {
    double m = sqrt(n);
    bool f = false;
    for (int i = 3; i <= m; i += 2) {
      if (n % i == 0) {
        x = i;
        f = true;
        break;
      }
    }
    if (!f)
      return true;
  }

  int t = n;
  for (size_t i = 0; i < 100; i++) {
    if (t % x != 0) {
      return false;
    }
    t /= x;
    if (t == 1) {
      return true;
    }
  }
}

int main() {
  int64_t N;
  cin >> N;
  int64_t a = 0, b = 0, c = 0, x, y, z;
  int64_t m = N;
  double r = sqrt(N);
  for (int i = 2; i <= m; i++) {
    if (!is_prime(i)) {
      continue;
    }
    if (N % i == 0) {
      a++;
      N /= i;
      m /= i;
    }
    // std::cout << "test " << i << " N " << N << '\\n';
    if (N <= i) {
      break;
    } else if (i > 5000000) {
      a++;
      break;
    }
  }
  // if (m<N && is_prime(N)) a++;
  std::cout << a << '\\n';
}


Error: TLE

Fixed submission:

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

bool is_prime(int n) {
  int x = 1;
  if (n < 2)
    return false;
  else if (n % 2 == 0)
    x = 2;
  else {
    double m = sqrt(n);
    bool f = false;
    for (int i = 3; i <= m; i += 2) {
      if (n % i == 0) {
        x = i;
        f = true;
        break;
      }
    }
    if (!f)
      return true;
  }

  int t = n;
  for (size_t i = 0; i < 100; i++) {
    if (t % x != 0) {
      return false;
    }
    t /= x;
    if (t == 1) {
      return true;
    }
  }
}

int main() {
  int64_t N;
  cin >> N;
  int64_t a = 0, b = 0, c = 0, x, y, z;
  int64_t m = N;
  double r = sqrt(N);
  for (int i = 2; i <= m; i++) {
    if (!is_prime(i)) {
      continue;
    }
    if (N % i == 0) {
      a++;
      N /= i;
      m /= i;
    }
    // std::cout << "test " << i << " N " << N << '\\n';
    if (N <= i) {
      break;
    } else if (a == 0 && i > r) {
      a++;
      break;
    }
  }
  // if (m<N && is_prime(N)) a++;
  std::cout << a << '\\n';
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

long long decompositPrime(long long n) {
  long long cnt = 0;
  map<long long, long long> m;

  for (long long p = 2; p * p <= n; p++) {
    if (n % p != 0)
      continue;
    int num = 0;

    while (n % p == 0) {
      num++;
      n /= p;
    }
    m[p] = num;
  }

  if (n != 1)
    m[n] = 1;

  for (auto itr : m) {
    long long index = 1;
    while (itr.second >= index) {
      cnt++;
      itr.second -= index;
      index++;
    }
  }

  return cnt;
}

int main() {
  //
  long long num;
  int cnt = 0;

  cin >> num;

  if (IsPrime(num) == true) {
    cout << 1;
    return 0;
  }

  cnt = decompositPrime(num);

  cout << cnt;
  //
}


Error: TLE

Fixed submission:

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

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

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

int main() {
  //
  long long num;
  int cnt = 0;

  cin >> num;

  if (IsPrime(num) == true) {
    cout << 1;
    return 0;
  }

  for (int i = 2; i < 6000003; i++) {
    if (num < i)
      break;
    if (IsPrime(i) == false)
      continue;
    for (int j = 1; j < 1000; j++) {
      long long tmp = pow(i, j);
      if (num % tmp == 0) {
        num /= tmp;
        cnt++;
      } else
        break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int trinum[11] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55};
int a[10000005] = {0};
int main() {
  long long n, sum = 0;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  long long j = 2;
  int m = int(sqrt(n));
  while (n % 2 == 0) {
    n /= 2;
    a[2]++;
  }
  int t = 3, ans = 0;
  while (n != 1 && t <= m) {
    while (n % t == 0) {
      n /= t;
      a[t]++;
    }
    t += 2;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= 10; j++) {
      if (trinum[j] > a[i]) {
        sum += (j - 1);
        break;
      }
    }
  }
  if (n > 1) {
    sum++;
  }
  cout << sum;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int trinum[11] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55};
int main() {
  long long n, sum = 0;
  cin >> n;
  long long j = 2;
  while (n != 1) {
    int k = 0;
    while (n % j == 0) {
      k++;
      n /= j;
    }
    int i = 1;
    while (trinum[i] <= k) {
      i++;
    }
    sum += (i - 1);
    j++;
  }
  cout << sum;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    ll temp = 0;
    while (n % i == 0) {
      n /= i;
      temp++;
    }
    if (temp)
      ans += (-1 + sqrt(1 + 8 * temp)) / 2;
  }
  if (n > 1)
    ans++;

  cout << ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

  ll n;
  cin >> n;
  int ans = 0;
  for (int i = 2; i * i <= n; i++) {
    ll temp = 0;
    while (n % i == 0) {
      if (n == 0)
        break;
      n /= i;
      temp++;
    }
    if (n == 0)
      break;
    if (temp)
      ans += (-1 + sqrt(1 + 8 * temp)) / 2;
  }
  if (n > 1)
    ans++;

  cout << ans << '\\n';

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

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<pair<long long, int>> v;
  for (long long i = 2; i * i < n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    pair<long long, int> p(i, cnt);
    v.emplace_back(p);
  }
  if (n != 1) {
    pair<long long, int> p(n, 1);
    v.emplace_back(p);
  }

  int ans = 0;
  for (auto p : v) {
    int a = p.second;
    int i = 1;
    while (i <= a) {
      a -= i;
      i++;
      ans++;
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<pair<long long, int>> v;
  for (int i = 2; i * i < n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    pair<long long, int> p(i, cnt);
    v.push_back(p);
  }
  if (n != 1) {
    pair<long long, int> p(n, 1);
    v.push_back(p);
  }

  int ans = 0;
  for (auto p : v) {
    int a = p.second;
    int i = 1;
    while (i <= a) {
      a -= i;
      i++;
      ans++;
    }
  }

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

// g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include <ostream>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

bool sosuhantei(ll x) {
  if (x == 1)
    return false;
  if (x == 2)
    return true;
  if (x == 3)
    return true;
  int i = 2;
  bool res = true;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      res = false;
      break;
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll M = N;
  ll max = 1;
  for (ll i = 1; i * i <= N; i++)
    max = i;
  vector<ll> num;
  map<ll, ll> cnt;
  for (int i = 2; i <= max; i++) {
    if (M % i == 0)
      num.push_back(i);
    while (M % i == 0) {
      cnt[i]++;
      M /= i;
    }
  }
  if (M != 1) {
    num.push_back(M);
    cnt[M]++;
  }
  /*
  rep(i,num.size()){
    cout << num[i] << " ";
  }
  cout << endl;
  */
  ll ans = 0;
  for (int i = 0; i < num.size(); i++) {
    int j = 1;
    while (cnt[num[i]] - j >= 0) {
      cnt[num[i]] -= j;
      j++;
      ans++;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

// g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include <ostream>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

bool sosuhantei(ll x) {
  if (x == 1)
    return false;
  if (x == 2)
    return true;
  if (x == 3)
    return true;
  int i = 2;
  bool res = true;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      res = false;
      break;
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll M = N;
  ll max = 1;
  for (ll i = 1; i * i <= N; i++)
    max = i;
  vector<ll> num;
  map<ll, ll> cnt;
  for (int i = 2; i <= max; i++) {
    if (M % i == 0)
      num.push_back(i);
    while (M % i == 0) {
      cnt[i]++;
      M /= i;
    }
    if (sosuhantei(M)) {
      num.push_back(M);
      cnt[M]++;
      break;
    }
  } /*
   rep(i,num.size()){
     cout << num[i] << " ";
   }
   cout << endl;
   */
  ll ans = 0;
  for (int i = 0; i < num.size(); i++) {
    int j = 1;
    while (cnt[num[i]] - j >= 0) {
      cnt[num[i]] -= j;
      j++;
      ans++;
    }
  }
  cout << ans << endl;
}
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 < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

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

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

  int ans = 0;
  for (auto x : mp) {
    int t = x.second;
    for (int i = 1; i < 100; i++) {
      if (i > t)
        break;
      ans++;
      t -= i;
    }
  }
  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 < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

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

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

  int ans = 0;
  for (auto x : mp) {
    int t = x.second;
    for (int i = 1; i < 100; i++) {
      if (i > t)
        break;
      ans++;
      t -= i;
    }
  }
  cout << ans << endl;

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

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

typedef long long ll;

unordered_map<ll, int> umap;

ll binarySearch(ll n, ll l, ll r) {

  ll mid, ans = l;
  while (l < r) {
    mid = l + (r - l) / 2;
    if (mid * (mid + 1) / 2 <= n) {
      ans = mid;
      l = mid + 1;
    }
    if (mid * (mid + 1) / 2 > n) {
      r = mid;
      ans = mid - 1;
    }
  }
  return ans;
}

void primefactors(ll n) {

  while (n % 2 == 0) {
    n = n / 2;
    umap[2]++;
  }

  for (ll i = 3; i <= sqrtl(n); i = i + 2) {
    while ((n % i) == 0) {
      umap[i]++;
      n /= i;
    }
  }

  if (n > 2) {
    umap[n]++;
  }
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  if (n == 1)
    cout << 0 << '\\n';
  else {

    primefactors(n);
    ll count = 0;

    // for(auto x: umap){
    //     cout << x.first << "->" << x.second << "\\n";
    // }

    for (auto x : umap) {
      if (x.second == 1) {
        count++;
        // cout << count << " ";
      } else {
        count += binarySearch(x.second, 1, x.second);
        // cout << count << " ";
      }
    }
    // cout << "\\n";
    cout << count << '\\n';
  }

  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

unordered_map<ll, int> umap;

ll binarySearch(ll n, ll l, ll r) {

  ll mid, ans = l;
  while (l < r) {
    mid = l + (r - l) / 2;
    if (mid * (mid + 1) / 2 <= n) {
      ans = mid;
      l = mid + 1;
    }
    if (mid * (mid + 1) / 2 > n) {
      r = mid;
      ans = mid - 1;
    }
  }
  return ans;
}

void primefactors(ll n) {

  while (n % 2 == 0) {
    n = n / 2;
    umap[2]++;
  }

  for (ll i = 3; i <= sqrt(n); i = i + 2) {
    while ((n % i) == 0) {
      umap[i]++;
    }
  }

  if (n > 2) {
    umap[n]++;
  }
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  if (n == 1)
    cout << 0 << '\\n';
  else {

    primefactors(n);
    ll count = 0;

    // for(auto x: umap){
    //     cout << x.first << "->" << x.second << "\\n";
    // }

    for (auto x : umap) {
      if (x.second == 1) {
        count++;
        // cout << count << " ";
      } else {
        count += binarySearch(x.second, 1, x.second);
        // cout << count << " ";
      }
    }
    // cout << "\\n";
    cout << count << '\\n';
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i, a, b) for (ll(i) = a; (i) < (ll)(b); (i)++)
using ipair = pair<ll, ll>;

vector<ll> prime_factorization3(ll a) {
  if (a <= 0)
    return {0};
  if (a == 1)
    return {1};

  vector<ll> ans;
  ll num = a;
  for (ll i = 2; i <= sqrt(a) + 1; i++) {
    while (num % i == 0) {
      ans.push_back(i);
      num = num / i;
    }
    if (num == 1)
      break;
  }
  if (num != 1)
    ans.push_back(num);
  set<ll> s(ans.begin(), ans.end());
  vector<ll> cnt(s.size(), 0);
  auto itr = s.begin();
  rep(i, 0, cnt.size()) {
    cnt[i] = count(ans.begin(), ans.end(), *itr);
    itr++;
  }
  return cnt;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1)
    cout << "0" << endl;
  else {
    ll ans = 0;
    vector<ll> cnt = prime_factorization3(N);
    for (ll i = 0; i < cnt.size(); i++) {
      ll tmpN = 1;
      while (1) {
        if ((tmpN + 1) * (tmpN + 2) > 2 * cnt[i])
          break;
        tmpN++;
      }
      ans += tmpN;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i, a, b) for (ll(i) = a; (i) < (ll)(b); (i)++)
using ipair = pair<ll, ll>;

bool prime_number(ll a) {
  ll flag = true;
  for (ll i = 2; i < sqrt(a) + 1; i++) {
    if (a % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}

vector<ll> prime_factorization3(ll a) {
  if (a <= 0)
    return {0};
  if (a == 1)
    return {1};
  if (prime_number(a))
    return {1};

  vector<ll> ans;
  ll num = a;
  for (ll i = 2; i <= a; i++) {
    if (prime_number(a)) {
      ans.push_back(num);
      break;
    }
    while (num % i == 0) {
      ans.push_back(i);
      num = num / i;
    }
    if (num == 1)
      break;
  }
  set<ll> s(ans.begin(), ans.end());
  vector<ll> cnt(s.size(), 0);
  auto itr = s.begin();
  rep(i, 0, cnt.size()) {
    cnt[i] = count(ans.begin(), ans.end(), *itr);
    itr++;
  }
  return cnt;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1)
    cout << "0" << endl;
  else {
    ll ans = 0;
    vector<ll> cnt = prime_factorization3(N);
    for (ll i = 0; i < cnt.size(); i++) {
      ll tmpN = 1;
      while (1) {
        if ((tmpN + 1) * (tmpN + 2) > 2 * cnt[i])
          break;
        tmpN++;
      }
      ans += tmpN;
    }
    cout << ans << endl;
  }
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5 + 1;
map<ll, ll> m;

void prime(ll n) {
  while (n > 1 && n % 2 == 0) {
    n /= 2;
    m[2]++;
  }

  for (ll i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      n /= i;
      m[i]++;
    }
  }

  if (n > 2)
    m[n]++;
}

void solve() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return;
  }
  prime(n);
  ll ans = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    ll k = (*itr).ff;
    ll c_val = 1;
    while (m[k] > 0) {
      if (m[k] - c_val < c_val + 1) {
        ans++;
        break;
      } else {
        ans++;
      }
      m[k] -= c_val;
      c_val++;
    }
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5 + 1;
map<ll, ll> m;

void prime(ll n) {
  while (n > 1 && n % 2 == 0) {
    n /= 2;
    m[2]++;
  }

  for (int i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      n /= i;
      m[i]++;
    }
  }

  if (n > 2)
    m[n]++;
}

void solve() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return;
  }
  prime(n);
  ll ans = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    ll k = (*itr).ff;
    ll c_val = 1;
    while (m[k] > 0) {
      if (m[k] - c_val < c_val + 1) {
        ans++;
        break;
      } else {
        ans++;
      }
      m[k] -= c_val;
      c_val++;
    }
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}