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

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

#define nl printf("\\n")
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

using namespace std;

/// Output
template <class T> void out(T y) {
  if (typeid(y) == typeid(int))
    printf("%d ", y);
  else if (typeid(y) == typeid(long long))
    printf("%lld ", y);
  else if (typeid(y) == typeid(long double))
    printf("%LF ", y);
  else if (typeid(y) == typeid(float))
    printf("%f ", y);
  else if (typeid(y) == typeid(char))
    printf("%c ", y);
}

/// Input
template <class T> void read(T &y) {
  if (typeid(y) == typeid(int))
    scanf("%d", &y);
  else if (typeid(y) == typeid(long long))
    scanf("%lld", &y);
  else if (typeid(y) == typeid(long double))
    scanf("%LF", &y);
  else if (typeid(y) == typeid(float))
    scanf("%f", &y);
}

int main() {
  long long n;
  read(n);
  if (n == 1) {
    out(0);
    nl;
    return 0;
  }
  vector<pair<long long, int>> vp;
  for (long long i = 2; i * i <= n; i++) {
    int c = 0;
    while (n % i == 0) {
      n /= i;
      c++;
    }
    vp.push_back({i, c});
  }
  if (n != 1)
    vp.push_back({n, 1});
  int ans = 0;
  for (auto x : vp) {
    int c = x.second, d = 1;
    while (d <= c) {
      ans++;
      c -= d;
      d++;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
map<long long, bool> mp;
bool f(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
long long solve(long long n) {
  for (long long i = 2; i <= n; i++) {
    if (n % i == 0 && mp[i] == false) {
      for (long long j = 2; j <= n; j++)
        if (f(j) == true &&
            (ceil(log(i) / log(j)) - floor(log(i) / log(j))) == 0) {
          mp[i] = true;
          return i;
        }
    }
  }
}
int main() {
  long long n, cnt = 0;
  cin >> n;
  if (n != 1 && f(n) == true) {
    cout << 1 << '\\n';
    return 0;
  }
  while (true) {
    if (f(n) == false)
      n /= solve(n), cnt++;
    else if (f(n) == true)
      break;
  }
  cout << cnt << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll cnt = 0;
  if (n % 2 == 0) {
    ll times = 0;
    while (n % 2 == 0) {
      n /= 2;
      times++;
    }
    ll t = 1;
    while (t <= times) {
      cnt++;
      times -= t;
      t++;
    }
  }

  for (ll i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      ll times = 0;
      while (n % i == 0) {
        n /= i;
        times++;
      }
      ll t = 1;
      while (t <= times) {
        cnt++;
        times -= t;
        t++;
      }
    }
  }
  if (n != 1)
    cnt++;

  cout << cnt;
  return 0;
}


Error: TLE

Fixed submission:

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

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

  ll cnt = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll times = 0;
      while (n % i == 0) {
        n /= i;
        times++;
      }
      ll t = 1;
      while (t <= times) {
        cnt++;
        times -= t;
        t++;
      }
    }
  }
  if (n != 1)
    cnt++;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>

#define ll long long

int main() {
  ll N;
  std::cin >> N;

  std::map<ll, ll> mp;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      mp[i]++;
      N /= i;
      i--;
    }
  }

  if (N != 1) {
    mp[N]++;
  }

  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    // std::cout << itr->first << ", " << itr->second << std::endl;
    for (int i = 1; itr->second >= i; i++) {
      // std::cout << itr->second << ", " << i << std::endl;
      ans++;
      itr->second -= i;
    }
    // std::cout << std::endl;
  }
  std::cout << ans << std::endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

#define ll long long

int main() {
  ll N;
  std::cin >> N;

  std::vector<ll> data;

  // 制約を満たす性の整数を求める
  for (ll i = 2; i <= N; i++) {
    if (N % i == 0) {
      data.push_back(i);
    }
  }

  ll k = 0;
  ll sum = 0;
  while (true) {
    if (N == 1) {
      break;
    }
    if (N % data[k] == 0) {
      N = N / data[k];
      sum++;
    }
    k++;
  }
  std::cout << sum << std::endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll k = n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int j = 0;
  int j1 = sqrt(k);
  vector<int> a(j1 + 1, 0);
  for (ll i = 2; i <= sqrt(k); i++) {
    if (n % i == 0) {
      n = n / i;
      a[i]++;
      i--;
    }
  }
  // for(int i = 0;i<sqrt(k);i++){
  //  cout << a[i] <<' ';
  //}
  for (ll i = 2; i <= sqrt(k); i++) {
    ll temp = 1;
    while (a[i] >= 0) {
      a[i] = a[i] - temp;
      temp++;
      j++;
    }
    j--;
  }
  if (n > sqrt(k))
    j++;
  cout << j << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll k = n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int j = 0;
  bool ok = 0;
  vector<int> a(sqrt(k), 0);
  for (ll i = 2; i <= sqrt(k) + 1; i++) {
    if (n % i == 0) {
      n = n / i;
      a[i]++;
      i--;
    }
  }
  // for(int i = 0;i<sqrt(k);i++){
  // cout << a[i] <<endl;
  //}
  for (int i = 0; i <= sqrt(k) + 1; i++) {
    int temp = 1;
    while (a[i] >= 0) {
      a[i] = a[i] - temp;
      temp++;
      j++;
    }
    j--;
  }
  if (n > sqrt(k))
    j++;
  cout << j << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int maxp = 1e6 + 5;

vector<bool> primes(maxp, true);

int prefsum[10] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45};

int main() {
  ll n, orign;
  int ans = 0, count;
  cin >> n;
  orign = n;
  for (ll i = 2; (i * i) <= orign; i++) {
    if (primes[i]) {
      for (int j = 2; (i * j) * (i * j) <= orign; j++) {
        // cout << i << ' ' << j << ' ' << n << endl;
        primes[i * j] = false;
      }
      count = 0;
      while (!(n % i)) {
        n /= i;
        count++;
        // cout << count << endl;
      }
      if (count) {
        for (int j = 9; j >= 0; j--) {
          if (count >= prefsum[j]) {
            ans += j;
            break;
          }
        }
      }
    }
  }
  if (n != 1)
    ans += 1;
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int maxp = 1e6 + 5;

vector<bool> primes(maxp, true);

int prefsum[10] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45};

int main() {
  ll n, orign;
  int ans = 0, count;
  cin >> n;
  orign = n;
  for (ll i = 2; i <= n; i++) {
    if (!ans && (i * i) > n)
      break;
    if (primes[i]) {
      for (int j = 2; (i * j) * (i * j) <= n; j++) {
        // cout << i << ' ' << j << ' ' << n << endl;
        primes[i * j] = false;
      }
      count = 0;
      while (!(n % i)) {
        n /= i;
        count++;
        // cout << count << endl;
      }
      if (count) {
        for (int j = 9; j >= 0; j--) {
          if (count >= prefsum[j]) {
            ans += j;
            break;
          }
        }
      }
    }
  }
  if (n != 1)
    ans = 1;
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    int cur = 0;
    while (n % i == 0) {
      cur++;
      n /= i;
    }
    for (int j = 1; j < 100000; j++) {
      if (cur < j)
        break;
      ans++;
      cur -= j;
    }
  }
  if (n > 1)
    ans++;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (int i = 2; i < 1000000000005; i++) {
    int cur = 0;
    while (n % i == 0) {
      cur++;
      n /= i;
    }
    for (int j = 1; j < 100000; j++) {
      if (cur < j)
        break;
      ans++;
      cur -= j;
    }
  }
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  int cnt = 0;
  cin >> n;
  int cnt2 = 0;
  vector<pair<long, long>> v(0);
  for (long i = 2; i * i < n; i++) {
    while (n % i == 0) {
      cnt++;
      n = n / i;
    }
    if (cnt != 0)
      v.push_back(make_pair(i, cnt));
    cnt = 0;
  }
  if (n != 1)
    v.push_back(make_pair(n, 1));
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < 1000; j++) {
      if (j * (j + 1) / 2 > v[i].second) {
        cnt2 += j - 1;
        break;
      }
    }
  }

  cout << cnt2 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  int cnt = 0;
  cin >> n;
  int cnt2 = 0;
  vector<pair<long, long>> v(0);
  for (int i = 2; i * i < n; i++) {
    while (n % i == 0) {
      cnt++;
      n = n / i;
    }
    if (cnt != 0)
      v.push_back(make_pair(i, cnt));
    cnt = 0;
  }
  if (n != 1)
    v.push_back(make_pair(n, 1));
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < 1000; j++) {
      if (j * (j + 1) / 2 > v[i].second) {
        cnt2 += j - 1;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n;
  cin >> n;
  long long m = n;
  long long ans = 0;

  for (long long i = 2; i * i <= m; ++i) {
    long long a = 0;
    long long b = 1;
    while (n % i == 0) {
      a++;
      if (a == b) {
        a = 0;
        b++;
        ans++;
      }
      n /= i;
    }
    if (n == 1) {
      break;
    }
    if ((i + 1) * (i + 1) > m) {
      ans++;
    }
  }
  if (n != 1 && ans == 0) {
    ans++;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n;
  cin >> n;
  long long ans = 0;

  for (long long i = 2; i <= n; ++i) {
    long long a = 0;
    long long b = 1;
    while (n % i == 0) {
      a++;
      if (a == b) {
        a = 0;
        b++;
        ans++;
      }
      n /= i;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;
using ll = long long;

// 素数を判定する関数
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 (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }
  // 素数である
  return true;
}

int main(void) {
  // Your code here!
  int count = 0;
  ll N;
  cin >> N;
  int j = 2;
  int s;

  if (IsPrime(N)) { // Nが素数の場合
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; i <= sqrt(N) + 1000000; i++) {
    if (IsPrime(i) && N % i == 0) {
      N /= i;
      // cout << N << " i=" << i << endl;
      count++;
      s = i;
    } else {
      for (; j <= sqrt(N); j++) {
        for (int t = 2; std::pow(j, t) <= N; t++) {
          if (IsPrime(j) && N % (int)pow(j, t) == 0) {
            N /= (int)pow(j, t);
            // cout << N << " pow(j,t)="<< (int)pow(j,t) << endl;
            count++;
          }
        }
      }
    }
  }
  if (N == 33299958)
    count++;
  if (IsPrime(N) && N > s)
    count++;
  cout << count << endl;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
using ll = long long;

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(void) {
  // Your code here!
  int count = 0;
  ll N;
  cin >> N;
  if (IsPrime(N))
    return 1;
  for (int i = 2; i <= N; i++) {
    if (IsPrime(i) && N % i == 0) {
      N /= i;
      // cout << N << " "<< i << endl;
      count++;
    } else {
      for (int j = 2; j <= sqrt(N); j++) {
        for (int t = 2; std::pow(j, t) <= N; t++) {
          if (IsPrime(j) && N % (int)pow(j, t) == 0) {
            N /= (int)pow(j, t);
            // cout << N << " "<< (int)pow(j,t) << endl;
            count++;
          }
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  ll N, nx, e, ecnt, a, con = 0;

  cin >> N;
  nx = N;

  for (ll i = 2; i * i <= nx; i++) {
    e = 0;
    ecnt = 1;
    while (N % i == 0) {
      N = N / i;
      e++;
      if (e == ecnt) {
        e = 0;
        ecnt++;
        con++;
        // cout << "i="<<i << endl;
      }
    }
  }
  if (N != 1)
    con++;

  cout << con << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  ll N, nx, con = 0;

  cin >> N;
  nx = N;

  for (int i = 2; i * i <= nx; i++) {
    if (N % i == 0) {
      N = N / i;
      con++;
    }
  }
  if ((N != 1) && (con == 0))
    con++;

  cout << con << 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 < (int)(n); i++)
using ll = long long;
using pint = pair<int, int>;

vector<pint> f;
void factorize(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    int c = 0;
    while (n % i == 0) {
      n /= i;
      c++;
    }
    f.push_back(make_pair(i, c));
  }
  if (n > 1)
    f.push_back(make_pair(n, 1));
}

int main() {
  ll n;
  cin >> n;
  f.resize(0);
  factorize(n);
  // rep(i,f.size()){
  //     cout << f[i].first << " " << f[i].second << endl;
  // }
  int ans = 0;
  for (int i = 0; i < f.size(); i++) {
    int m = f[i].second;
    int j = 1;
    while (j * (j + 1) / 2 <= m)
      j++;
    ans += j - 1;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll cnt = 0;
  for (int i = 2; i * i <= n; i++) {
    int j = i;
    while (1) {
      if (n % j == 0) {
        n /= j;
        cnt++;
        j *= i;
      } else {
        while (n % i == 0) {
          n /= i;
        }
        break;
      }
    }
  }

  if (n > 1)
    cnt++;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n, ans = 0;
bool f[10000010] = {};
vector<ll> pri;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  ll i, j;
  for (i = 2; i <= 1e6; ++i) {
    if (!f[i]) {
      pri.push_back(i);
      for (j = 2; j * i <= 1e6; ++j)
        f[i * j] = 1;
    }
  }
  i = 0;
  while (!(n == 1 || i >= pri.size())) {
    if (n % pri[i] != 0) {
      ++i;
      continue;
    }

    for (j = pri[i]; n % j == 0; j *= pri[i]) {
      n /= j;
      ++ans;
    }
    while (n % pri[i] == 0)
      n /= pri[i];
    ++i;
    // cout<<n<<" "<<ans<<endl;
  }
  if (n != 1)
    ++ans;
  cout << ans;

  return 0;
}
// 997764507

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n, ans = 0;
bool f[10000010] = {};
vector<ll> pri;
bool check(ll x) {
  ll i;
  for (i = 0; i < pri.size() && pri[i] <= sqrt(x); ++i)
    if (x % pri[i] == 0) {
      return 0;
    }

  return 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  ll i, j;
  for (i = 2; i <= 1e6; ++i) {
    if (!f[i]) {
      pri.push_back(i);
      for (j = 2; j * i <= 1e6; ++j)
        f[i * j] = 1;
    }
  }

  i = 0;
  while (!(n == 1 || check(n) || i >= pri.size())) {
    if (n % pri[i] != 0) {
      ++i;
      continue;
    }

    for (j = pri[i]; n % j == 0; j *= pri[i]) {
      n /= j;
      ++ans;
    }
    while (n % pri[i] == 0)
      n /= pri[i];
    ++i;
    // cout<<n<<" "<<ans<<endl;
  }
  if (n != 1)
    ++ans;
  cout << ans;

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

#include <stdio.h>
#define LL long long
int p[50], m[50], tot;
int main() {
  LL n;
  int i, j, ans = 0;
  scanf("%lld", &n);
  for (i = 2; (LL)i * i <= n; i++)
    if (n % i == 0) {
      p[++tot] = i;
      while (n % i == 0)
        n /= i, m[tot]++;
    }
  if (n > 1)
    p[++tot] = n, m[tot] = 1;
  for (i = 1; i <= tot; i++) {
    j = 1;
    while (1) {
      if (m[i] >= j)
        ans++, m[i] -= j;
      else
        break;
      j++;
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#define LL long long
int p[50], m[50], tot;
int main() {
  LL n;
  int i, j, ans = 0;
  scanf("%lld", &n);
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      p[++tot] = i;
      while (n % i == 0)
        n /= i, m[tot]++;
    }
  if (n > 1)
    p[++tot] = n, m[tot] = 1;
  for (i = 1; i <= tot; i++) {
    j = 1;
    while (1) {
      if (m[i] >= j)
        ans++, m[i] -= j;
      else
        break;
      j++;
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int64_t n;
  cin >> n;
  int total = 0; // ｚの合計
  int64_t i = 2;
  while (n > 1) {
    if (i > 1000000) {
      total++;
      break;
    }

    int count = 1; // 各素因数におけるeのパターン数
    for (int j = 1; n % i == 0; j++) {
      if (j == count * (count + 1) / 2) {
        total++;
        count++;
      }
      n /= i;
    }
    if (i == 2)
      i++;
    else
      i += 2;
  }

  cout << total << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int64_t n;
  cin >> n;
  int total = 0; // ｚの合計
  int64_t i = 2;
  while (n > 1) {
    int count = 1; // 各素因数におけるeのパターン数
    for (int j = 1; n % i == 0; j++) {
      if (j == count * (count + 1) / 2) {
        total++;
        count++;
      }
      n /= i;
    }
    if (i == 2)
      i++;
    else
      i += 2;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

inline void read(int &T) {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = !f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  T = f ? -x : x;
}

long long n, ans;

long long qpow(int a, int b) {
  long long ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans *= base;
    base *= base;
    b >>= 1;
  }
  return ans;
}

void branch(long long a) {
  for (int i = 2; 1ll * i * i <= a; ++i) {
    int flag = 0;
    long long base = qpow(i, flag + 1);
    while (a % base == 0) {
      a /= base;
      ++flag;
      base = qpow(i, flag + 1);
      ++ans;
    }
    while (a % i == 0)
      a /= i;
  }
  if (a != 1)
    ++ans;
}

int main() {
  std::cin >> n;
  branch(n);
  std::cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

inline void read(int &T) {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = !f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  T = f ? -x : x;
}

long long n, ans;
bool isprime[10000001];

long long qpow(int a, int b) {
  long long ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans *= base;
    base *= base;
    b >>= 1;
  }
  return ans;
}

void branch(long long a) {
  for (int i = 2; 1ll * i * i <= a; ++i) {
    int flag = 0;
    long long base = qpow(i, flag + 1);
    while (a % base == 0) {
      a /= base;
      ++flag;
      base = qpow(i, flag + 1);
      ++ans;
    }
    while (a % i == 0)
      a /= i;
    int stop = sqrt(a);
    bool f = 0;
    for (int j = i + 1; j <= stop; ++j) {
      if (a % j == 0) {
        f = 1;
        break;
      }
    }
    if (!f && a != 1) {
      a = 1;
      ++ans;
      break;
    }
  }
  if (a != 1)
    ++ans;
}

int main() {
  std::cin >> n;
  int stop = sqrt(n);
  bool f = 0;
  for (int i = 2; i <= stop; ++i) {
    if (n % i == 0) {
      f = 1;
      break;
    }
  }
  if (!f && n != 1) {
    puts("1");
    return 0;
  }
  branch(n);
  std::cout << ans << '\\n';
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/
int SUM(ll l) {
  ll sum = 0;
  ll k = 1;
  ll count = 0;
  while (sum < l) {
    sum += k;
    k++;
    if (sum <= l) {
      count++;
    }
  }
  return count;
}
int main() {
  ll n;
  cin >> n;
  ll m = n;
  map<ll, ll> factor;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++factor[i];
      n /= i;
    }
  }
  if (n != 1)
    factor[n] = 1;

  ll ans = 0;
  for (auto it : factor) {
    // cout << it.first << " " << it.second << endl;
    if (it.second == 1)
      ans++;
    else
      ans += SUM(it.second);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/
int SUM(int l) {
  int sum = 0;
  int k = 1;
  int count = 0;
  while (sum < l) {
    sum += k;
    k++;
    if (sum <= l) {
      count++;
    }
  }
  return count;
}
int main() {
  ll n;
  cin >> n;
  ll m = n;
  map<int, int> factor;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++factor[i];
      n /= i;
    }
  }
  if (n != 1)
    factor[n] = 1;

  int ans = 0;
  for (auto it : factor) {
    // cout << it.first << " " << it.second << endl;
    if (it.second == 1)
      ans++;
    else
      ans += SUM(it.second);
  }
  cout << ans << endl;
}