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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rept(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a, b) memset(a, b, sizeof a)
#define mp make_pair
#define dd(x) cout << #x << "=" << x << " "
#define de(x) cout << #x << "=" << x << "\\n"
#define debug() cout << "I love Miyamizu Mitsuha forever.\\n"
const int inf = 0x3f3f3f3f;
ll cal(ll x) {
  ll ans = 0, plus = 1, val = 0;
  while (x >= val + plus) {
    ans++;
    val += plus;
    plus++;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x;
  cin >> x;
  if (x == 1) {
    cout << "0\\n";
    return 0;
  }
  ll ans = 0;
  for (ll i = 2; i * i < x; i++) {
    if (x % i == 0) {
      ll val = 0;
      while (x % i == 0) {
        val++;
        x /= i;
      }
      ans += cal(val);
    }
  }
  if (x != 1)
    ans++;
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rept(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a, b) memset(a, b, sizeof a)
#define mp make_pair
#define dd(x) cout << #x << "=" << x << " "
#define de(x) cout << #x << "=" << x << "\\n"
#define debug() cout << "I love Miyamizu Mitsuha forever.\\n"
const int inf = 0x3f3f3f3f;
int cal(int x) {
  int ans = 0, plus = 1, val = 0;
  while (x >= val + plus) {
    ans++;
    val += plus;
    plus++;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x;
  cin >> x;
  if (x == 1) {
    cout << "0\\n";
    return 0;
  }
  int ans = 0;
  for (int i = 2; i * i < x; i++) {
    if (x % i == 0) {
      int val = 0;
      while (x % i == 0) {
        val++;
        x /= i;
      }
      ans += cal(val);
    }
  }
  if (x != 1)
    ans++;
  cout << ans << "\\n";
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool isPrime(ll n) {
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  for (ll i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  ll N, N_save;
  cin >> N;
  N_save = N;
  ll cnt = 0;
  vector<ll> div;
  div.clear();

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

  if (isPrime(N)) {
    cout << 1 << endl;
    return 0;
  }

  for (ll i = 2; i <= sqrt(N); i++) {
    if (isPrime(i) != 1)
      continue;
    ll tmp = i;
    while (N % i == 0) {
      div.push_back(tmp);
      N /= i;
      tmp *= i;
    }
  }

  if (isPrime(N)) {
    bool flag = true;
    for (int i = 0; i < int(div.size()); i++) {
      if (div[i] == N) {
        flag = false;
      }
    }
    if (flag) {
      div.push_back(N);
    }
  }

  sort(div.begin(), div.end());

  for (int i = 0; i < int(div.size()); i++) {
    if (N_save % div[i] == 0) {

      N_save /= div[i];

      cnt++;
    }
  }

  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

bool isPrime(ll n) {
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  for (ll i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  ll N, N_save;
  cin >> N;
  N_save = N;
  ll cnt = 0;
  vector<ll> div;
  div.clear();

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

  if (isPrime(N)) {
    cout << 1 << endl;
    return 0;
  }

  for (ll i = 2; i <= N; i++) {
    if (isPrime(i) != 1)
      continue;
    ll tmp = i;
    while (N % tmp == 0) {
      div.push_back(tmp);
      N /= tmp;
      tmp *= i;
    }
  }

  if (isPrime(N)) {
    bool flag = true;
    for (int i = 0; i < int(div.size()); i++) {
      if (div[i] == N) {
        flag = false;
      }
    }
    if (flag) {
      div.push_back(N);
    }
  }

  sort(div.begin(), div.end());

  for (int i = 0; i < int(div.size()); i++) {
    if (N_save % div[i] == 0) {

      N_save /= div[i];

      cnt++;
    }
  }

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

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

class smart_sieve {
  intmax_t L, R, M;
  vector<int> small;
  vector<vector<intmax_t>> large;
  vector<intmax_t> aux;

public:
  smart_sieve(intmax_t L, intmax_t R) : L(L), R(R), M(sqrt(R) + 1) {
    small.resize(M);
    iota(small.begin(), small.end(), 0);
    large.resize(R - L);
    aux.assign(R - L, 1);

    for (intmax_t i = 2; i * i < R; i++) {
      if (small.at(i) < i)
        continue;
      small.at(i) = i;
      for (intmax_t j = i * i; j < M; j += i)
        if (small.at(j) == j)
          small.at(j) = i;

      for (intmax_t j = (L + i - 1) / i * i; j < R; j += i) {
        intmax_t k = j;
        do {
          if (aux.at(j - L) * aux.at(j - L) > R)
            break;
          large.at(j - L).push_back(i);
          aux.at(j - L) *= i;
          k /= i;
        } while (k % i == 0);
      }
    }
  }
  vector<intmax_t> factor(intmax_t n) {
    assert(L <= n && n < R);
    vector<intmax_t> res = large.at(n - L);
    n /= aux.at(n - L);
    if (n >= M) {
      res.push_back(n);
      return res;
    }
    while (n > 1) {
      res.push_back(small.at(n));
      n /= small.at(n);
    }
    return res;
  }
};

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

  smart_sieve ss(n, n + 1);
  vector<intmax_t> vec = ss.factor(n);
  int ans = 0;
  int insu = 1;
  int nax = 1;
  int cnum = 1;
  for (auto num : vec) {
    if (insu != num) {
      insu = num;
      cnum = 1;
      nax = num;
      ans++;
    } else if (nax < cnum * num) {
      nax = cnum * num;
      cnum = 1;
      ans++;
    } else {
      cnum *= num;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

ll prime_factorization(int n) {
  vector<ll> min_factor(n + 1);
  std::iota(min_factor.begin(), min_factor.end(), 0LL);
  for (ll i = 2; i * i < n + 1; i++) {
    if (min_factor.at(i) < i)
      continue;
    for (ll j = i * i; j < n + 1; j += i) {
      if (min_factor.at(j) == j)
        min_factor.at(j) = i;
    }
  }
  set<ll> res;
  while (n > 1) {
    res.insert(min_factor.at(n));
    n /= min_factor.at(n);
  }
  return res.size();
}

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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  if (IsPrime(n)) {
    cout << 1 << '\\n';
    return 0;
  }
  int ans = 0;
  ll i;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (prime_factorization(i) != 1)
        continue;
      ans++;
      n /= i;
    }
  }
  if ((IsPrime(n) || prime_factorization(n) == 1) && i <= n)
    ans++;
  cout << ans << '\\n';

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define rep(i, a, n) for (int i = a; i < n; ++i)
typedef vector<int> vi;
typedef long long ll;
const int mod = 1e9 + 7;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
vector<ll> q;

ll getAns(ll m) {
  ll x = 0;
  auto it = upper_bound(all(q), m) - q.begin() - 1;
  return it;
}

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 0; i <= 1e6; i++) {
    q.pb(((i + 1) * i) / 2);
  }
  for (ll i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    ans += getAns(cnt);
  }
  if (n > 1)
    ans++;
  cout << ans;
}

int main() {
  Blue;
  int test = 1;
  // cin>>test;
  while (test--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define rep(i, a, n) for (int i = a; i < n; ++i)
typedef vector<int> vi;
typedef long long ll;
const int mod = 1e9 + 7;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
vector<ll> q;

ll getAns(ll m) {
  ll x = 0;
  auto it = upper_bound(all(q), m) - q.begin() - 1;
  return it;
}

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 0; i <= 1e6; i++) {
    q.pb(((i + 1) * i) / 2);
  }
  for (int i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    ans += getAns(cnt);
  }
  if (n > 1)
    ans++;
  cout << ans;
}

int main() {
  Blue;
  int test = 1;
  // cin>>test;
  while (test--)
    solve();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\\n"

const int mod = 1e9 + 7;

inline int add(int a, int b) {
  int res = a + b;
  if (res >= mod)
    res -= mod;
  return res;
}
inline int sub(int a, int b) {
  int res = a - b;
  if (res < 0)
    res += mod;
  return res;
}
inline int mul(int a, int b) { return (a * b) % mod; }

void solve() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return;
  }
  vector<int> v;
  bool is = true;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      is = false;
      break;
    }
  if (is) {
    cout << 1 << endl;
    return;
  }
  int x = n;
  int lim = 1e6;
  for (int i = 2; i <= min(lim, x); i++) {
    if (x % i == 0) {
      int cnt = 0;
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      v.push_back(cnt);
    }
  }
  if (x != 1)
    v.push_back(1);
  int ans = 0;
  for (int a : v) {
    int i = 1;
    while (i * (i + 1) / 2 <= a) {
      i++;
    }
    i--;
    ans += i;
  }
  cout << ans << endl;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);

  int T = 1;
  // cin >> T;

  while (T--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\\n"

const int mod = 1e9 + 7;

inline int add(int a, int b) {
  int res = a + b;
  if (res >= mod)
    res -= mod;
  return res;
}
inline int sub(int a, int b) {
  int res = a - b;
  if (res < 0)
    res += mod;
  return res;
}
inline int mul(int a, int b) { return (a * b) % mod; }

void solve() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return;
  }
  vector<int> v;
  bool is = true;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      is = false;
      break;
    }
  if (is) {
    cout << 1 << endl;
    return;
  }
  int x = n;
  int lim = 1e6;
  for (int i = 2; i <= max(lim, x); i++) {
    if (x % i == 0) {
      int cnt = 0;
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      v.push_back(cnt);
    }
  }
  if (x != 1)
    v.push_back(1);
  int ans = 0;
  for (int a : v) {
    int i = 1;
    while (i * (i + 1) / 2 <= a) {
      i++;
    }
    i--;
    ans += i;
  }
  cout << ans << endl;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);

  int T = 1;
  // cin >> T;

  while (T--) {
    solve();
  }
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, ans = 0;
  cin >> n;
  vector<int> v;
  for (int i = 1; i <= 100; i++) {
    v.push_back(i * (i + 1) / 2);
  }
  for (ll i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt)
      ans += upper_bound(v.begin(), v.end(), cnt) - v.begin();
  }
  if (n != 1)
    ans++;
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, ans = 0;
  cin >> n;
  vector<int> v;
  for (int i = 1; i <= 100; i++) {
    v.push_back(i * (i + 1) / 2);
  }
  for (int i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt)
      ans += upper_bound(v.begin(), v.end(), cnt) - v.begin();
  }
  if (n != 1)
    ans++;
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

bool prime_test(int n) {
  bool is_prime = true;
  if (n == 1)
    is_prime = false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      is_prime = false;
      break;
    }
  }
  return is_prime;
}

int bi_scale(int a) {
  int p;
  for (long long int i = 0; i < 100; i++) {
    if (a >= i * (i + 1) / 2 && a < (i + 2) * (i + 1) / 2) {
      p = i;
      break;
    }
  }
  return p;
}

int main() {

  long long int n;
  cin >> n;

  long long int m = n;
  vector<long long int> f;
  for (long long int i = 2; i * i <= n; i++) {
    if (m % i == 0) {
      f.push_back(i);
      m = m / i;
      i--;
    }
    if (m == 1)
      break;
  }
  if (m != 1)
    f.push_back(m);

  vector<int> a;
  int b[100] = {};
  for (int i = 0; i < f.size(); i++) {
    int c = 0;
    for (int j = 0; j < a.size(); j++) {
      if (f[i] == a[j]) {
        c++;
        b[j]++;
      }
    }
    if (c == 0)
      a.push_back(f[i]);
  }

  int q = 0;

  for (int i = 0; i < a.size(); i++) {
    q += bi_scale(b[i] + 1);
  }

  cout << q << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int bi_scale(int a) {
  int p;
  for (int i = 0; i < 100; i++) {
    if (a >= i * (i + 1) / 2 && a < (i + 2) * (i + 1) / 2) {
      p = i;
      break;
    }
  }
  return p;
}

int main() {

  long long int n;
  cin >> n;

  long long int m = n;
  vector<long long int> f;
  for (int i = 2; i * i < n; i++) {
    if (m % i == 0) {
      f.push_back(i);
      m = m / i;
      i--;
    }
    if (m == 1)
      break;
  }
  if (m != 1)
    f.push_back(m);

  vector<int> a;
  int b[100] = {};
  for (int i = 0; i < f.size(); i++) {
    int c = 0;
    for (int j = 0; j < a.size(); j++) {
      if (f[i] == a[j]) {
        c++;
        b[j]++;
      }
    }
    if (c == 0)
      a.push_back(f[i]);
  }

  int q = 0;

  for (int i = 0; i < a.size(); i++) {
    q += bi_scale(b[i] + 1);
  }

  cout << q << 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++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs;
  for (ll i = 2; i * i <= n; i++) {
    int kosuu = 0;
    while (n % i == 0) {
      n /= i;
      kosuu++;
    }
    fs.emplace_back(i, kosuu);
  }
  if (n != 1)
    fs.emplace_back(n, 1);
  int ans = 0;
  for (auto p : fs) {
    int i = 1;
    while (p.second - i >= 0) {
      p.second -= i;
      i++;
      ans++;
    }
  }
  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;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs;
  for (int i = 2; i * i <= n; i++) {
    int kosuu = 0;
    while (n % i == 0) {
      n /= i;
      kosuu++;
    }
    fs.emplace_back(i, kosuu);
  }
  if (n != 1)
    fs.emplace_back(n, 1);
  int ans = 0;
  for (auto p : fs) {
    int i = 1;
    while (p.second - i >= 0) {
      p.second -= i;
      i++;
      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++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  ll n;
  cin >> n;
  vector<ll> kosuu(10000, 0);
  ll ruton = pow(n, 0.5);
  ll i = 2, j = -1;
  int ans = 0;
  while (n != 1) {
    if (n % i == 0)
      j++;
    while (n % i == 0) {
      kosuu[j]++;
      n /= i;
    }
    i++;
    if (i == ruton) {
      if (n == 1)
        break;
      else {
        ans++;
        break;
      }
    }
  }

  rep(i, 10000) {
    int j = 1;
    while (kosuu[i] - j >= 0) {
      kosuu[i] -= j;
      j++;
      ans++;
    }
  }
  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;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  ll n;
  cin >> n;
  vector<ll> kosuu(10000, 0);
  ll i = 2, j = -1;
  while (n != 1) {
    if (n % i == 0)
      j++;
    while (n % i == 0) {
      kosuu[j]++;
      n /= i;
    }
    i++;
  }
  int ans = 0;
  rep(i, 10000) {
    int j = 1;
    while (kosuu[i] - j >= 0) {
      kosuu[i] -= j;
      j++;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
// #include <math.h>
#include <iomanip>
// #include <vector>

using namespace std;

int answer = 0;
void cal(unsigned long long n) {
  unsigned long long a = 2;
  int trigger = 1;
  int omomi = 2;
  int loop_num = 0;
  while (n >= a * a) {

    if (n % a == 0) {
      loop_num += 1;
      if (loop_num == trigger) {
        ++answer;
        trigger = trigger + omomi;
        ++omomi;
        // loop_num = 0;
      }
      n /= a;
    } else {
      trigger = 1;
      omomi = 2;
      loop_num = 0;
      if (a == 2) {
        a++;
      } else {
        a += 2;
      }
    }
  }
  if (n != a) {
    ++answer;
  } else {
    loop_num += 1;
    if (loop_num == trigger) {
      ++answer;
      // cout << "innn" << endl;
    }
  }
}

int main() {
  unsigned long long N;
  cin >> N;
  // soinsu bunkai
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  cal(N);
  // cout << m[2] << endl;

  cout << answer << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int answer = 0;
void cal(unsigned long long n) {
  int a = 2;
  int trigger = 1;
  int omomi = 1;
  int loop_num = 0;
  while (n >= a * a) {

    if (n % a == 0) {
      loop_num += 1;
      if (loop_num == trigger) {
        ++answer;
        trigger = trigger + omomi;
        //++omomi;
        loop_num = 0;
      }
      n /= a;
    } else {
      trigger = 1;
      omomi = 1;
      loop_num = 0;
      if (a == 2) {
        a++;
      } else {
        a += 2;
      }
    }
  }
  if (n != a) {
    ++answer;
  } else {
    loop_num += 1;
    if (loop_num == trigger) {
      ++answer;
      // cout << "innn" << endl;
    }
  }
}

int main() {
  unsigned long long N;
  cin >> N;
  // soinsu bunkai
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  cal(N);
  // cout << m[2] << endl;

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

// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;

int main() {
  // fios;
  ll n;
  cin >> n;
  unordered_map<ll, ll> mp;
  if (n == 1) {
    puts("0");
    return 0;
  }

  ll ans = 0;

  ll f = 2;
  while (n % f == 0) {
    mp[f]++;
    n /= f;
    f *= 2;
  }

  for (ll i = 3; i * i <= n; i += 2) {
    ll t = i;
    while (n % t == 0) {
      mp[t]++;
      ans++;
      n /= t;
      t *= i;
      if (n == 0)
        break;
    }
    while (n % i == 0)
      n /= i, mp[i]++;
  }
  // DEBUG(ans);
  if (n > 2)
    mp[n]++;
  cout << mp.size() << endl;
}

Error: TLE

Fixed submission:

// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;

int main() {
  // fios;
  ll n;
  cin >> n;
  unordered_map<ll, ll> mp;
  if (n == 1) {
    puts("0");
    return 0;
  }
  while (n % 2 == 0) {
    mp[2]++;
    n /= 2;
  }

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

  if (n > 2)
    mp[n]++;

  ll ans = 0;

  for (auto &p : mp) {
    ans += floor((-1 + sqrt(8 * p.second + 1)) / 2);
  }
  cout << ans << endl;
}