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

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void primeFactors(ll n) {
  // Print the number of 2s that divide n
  ll c = 0;
  vector<ll> x;
  ll i;
  while (n % 2 == 0) {
    // cout << 2 << " ";
    c++;
    n = n / 2;
  }
  if (c > 0)
    x.push_back(c);

  // n must be odd at this point. So we can skip
  // one element (Note i = i +2)
  for (i = 3; i <= sqrt(n); i = i + 2) {
    c = 0;
    // While i divides n, print i and divide n
    while (n % i == 0) {
      // cout << i << " ";
      n = n / i;
      c++;
    }
    if (c > 0)
      x.push_back(c);
  }

  // This condition is to handle the case when n
  // is a prime number greater than 2
  if (n > 2) {
    // cout << n << " ";
    x.push_back(1);
  }

  ll j;
  ll ans = 0;
  for (i = 0; i < x.size(); i++) {
    ll j;
    for (j = 1;; j++) {
      if (((j * (j + 1)) / 2) > x[i]) {
        break;
      }
    }
    ans += j - 1;
  }
  cout << ans << endl;
}

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  if (n == 1)
    cout << 0 << endl;
  else
    primeFactors(n);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int

using namespace std;
void sieveOfEratosthenes(ll N, ll s[]) {
  // Create a boolean array "prime[0..n]" and
  // initialize all entries in it as false.
  vector<bool> prime(N + 1, false);

  // Initializing smallest factor equal to 2
  // for all the even numbers
  for (ll i = 2; i <= N; i += 2)
    s[i] = 2;

  // For odd numbers less then equal to n
  for (ll i = 3; i <= N; i += 2) {
    if (prime[i] == false) {
      // s(i) for a prime is the number itself
      s[i] = i;

      // For all multiples of current prime number
      for (ll j = i; j * i <= N; j += 2) {
        if (prime[i * j] == false) {
          prime[i * j] = true;

          // i is the smallest prime factor for
          // number "i*j".
          s[i * j] = i;
        }
      }
    }
  }
}
void generatePrimeFactors(ll N) {
  // s[i] is going to store smallest prime factor
  // of i.
  ll s[N + 1];

  // Filling values in s[] using sieve
  sieveOfEratosthenes(N, s);

  // printf("Factor Power\\n");

  ll curr = s[N]; // Current prime factor of N
  ll cnt = 1;     // Power of current prime factor
  ll ans = 0;
  // Printing prime factors and their powers
  while (N > 1) {
    N /= s[N];

    // N is now N/s[N].  If new N als has smallest
    // prime factor as curr, increment power
    if (curr == s[N]) {
      cnt++;
      continue;
    }

    // printf("%d\\t%d\\n", curr, cnt);
    ll j;
    for (j = 1;; j++) {
      if (((j * (j + 1)) / 2) > cnt) {
        break;
      }
    }
    ans += j - 1;

    // Update current prime factor as s[N] and
    // initializing count as 1.
    curr = s[N];
    cnt = 1;
  }
  // cout<<"Answer  ="<<ans<<endl;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  if (n == 1)
    cout << 0 << endl;
  else
    generatePrimeFactors(n);
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

// #pragma GCC optimize(2)
// #pragma comment(linker, "/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
typedef long long ll;
typedef pair<ll, ll> P;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int N = 1010;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } // NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int p[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;
  ll m = n;
  int ans = 0;
  rep(i, 2, m / i + 1) {
    if (n % i == 0) {
      int j = i;
      while (n % j == 0) {
        ans++;
        n /= j;
        j *= i;
      }
      while (n % i == 0) {
        n /= i;
      }
    }
  }

  if (n > 1)
    ans++;

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

// #pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
const ll limit = 1000000;
bitset<limit + 1> notPrime;
ll next(int i) {
  while (notPrime[i] != 0) {
    i++;
  }
  return i;
}
unordered_map<ll, bool> pt;
bool isPrime(ll num) {
  if (pt.find(num) != pt.end()) {
    return pt[num];
  }
  if (num == 1) {
    pt.insert({num, false});
    return false;
  }
  if (num == 2 || num == 3) {
    pt.insert({num, true});
    return true;
  }
  if (num % 6 != 1 && num % 6 != 5) {
    pt.insert({num, false});
    return false;
  }
  if (num < limit && notPrime[num] == 0) {
    pt.insert({num, true});
    return true;
  } else if (num < limit && notPrime[num] == 1) {
    pt.insert({num, false});
    return false;
  }

  ll t = sqrtl(num);
  for (ll i = 5; i < t + 1; i++) {
    if (num % i == 0 || num % (i + 2) == 0) {
      pt.insert({num, false});
      return false;
    }
  }
  pt.insert({num, true});
  return true;
}

int main() {
  long long b = limit;

  long long s = sqrtl(b) + 1;

  for (ll i = 2; i <= s; i++) {
    if (!notPrime[i]) {
      for (ll j = i; j <= b / i; j++) {
        notPrime[i * j] = 1;
      }
    }
  }

  ll n;
  cin >> n;
  s = n / 2;
  ll ans = 0;
  if (n > limit) {
    if (isPrime(n)) {
      cout << 1 << endl;
      return 0;
    }
  }

  for (ll i = 2; i <= n; i = next(i + 1)) {
    ll k = i;
    while (k <= n) {
      ll d = n / k;
      if (k * d == n) {
        ans++;
      } else {
        break;
      }

      n = d;
      k *= i;
    }
    if (n > limit) {
      if (isPrime(n)) {
        ans++;
        break;
      }
    }
  }

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

// #pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)

bitset<100000001> notPrime;
ll next(int i) {
  while (notPrime[i] != 0) {
    i++;
  }
  return i;
}
unordered_map<ll, bool> pt;
bool isPrime(ll num) {
  if (pt.find(num) != pt.end()) {
    return pt[num];
  }
  if (num == 1) {
    pt.insert({num, false});
    return false;
  }
  if (num == 2 || num == 3) {
    pt.insert({num, true});
    return true;
  }
  if (num % 6 != 1 && num % 6 != 5) {
    pt.insert({num, false});
    return false;
  }
  if (num < 100000000 && notPrime[num] == 0) {
    pt.insert({num, true});
    return true;
  } else if (num < 100000000 && notPrime[num] == 1) {
    pt.insert({num, false});
    return false;
  }

  ll t = sqrtl(num);
  for (ll i = 5; i < t + 1; i++) {
    if (num % i == 0 || num % (i + 2) == 0) {
      pt.insert({num, false});
      return false;
    }
  }
  pt.insert({num, true});
  return true;
}

int main() {
  long long b = 100000000;

  long long s = sqrtl(b) + 1;

  for (ll i = 2; i <= s; i++) {
    if (!notPrime[i]) {
      for (ll j = i; j <= b / i; j++) {
        notPrime[i * j] = 1;
      }
    }
  }

  ll n;
  cin >> n;
  s = n / 2;
  ll ans = 0;
  if (n > 100000000) {
    if (isPrime(n)) {
      cout << 1 << endl;
      return 0;
    }
  }

  for (ll i = 2; i <= n; i = next(i + 1)) {
    ll k = i;
    while (k <= n) {
      ll d = n / k;
      if (k * d == n) {
        ans++;
      } else {
        break;
      }

      n = d;
      k *= i;
    }
    if (n > 100000000) {
      if (isPrime(n)) {
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

// #pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)

bitset<100000001> notPrime;
ll next(int i) {
  while (notPrime[i] != 0) {
    i++;
  }
  return i;
}

bool isPrime(ll num) {
  if (num == 1) {
    return false;
  }
  if (num == 2 || num == 3) {
    return true;
  }
  if (num % 6 != 1 && num % 6 != 5) {
    return false;
  }
  if (num < 100000000 && notPrime[num] == 0) {
    return true;
  } else if (num < 100000000 && notPrime[num] == 1) {
    return false;
  }

  ll t = sqrtl(num);
  for (ll i = 5; i < t + 1; i++) {
    if (num % i == 0 || num % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  long long b = 100000000;

  long long s = sqrtl(b) + 1;

  for (ll i = 2; i <= s; i++) {
    if (!notPrime[i]) {
      for (ll j = i; j <= b / i; j++) {
        notPrime[i * j] = 1;
      }
    }
  }

  ll n;
  cin >> n;
  s = n / 2;
  ll ans = 0;
  if (isPrime(n)) {
    cout << 1 << endl;
    return 0;
  }
  for (ll i = 2; i <= n; i = next(i + 1)) {
    ll k = i;
    while (k <= n) {
      ll d = n / k;
      if (k * d == n) {
        ans++;
      } else {
        break;
      }

      n = d;
      k *= i;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll gcd(ll x, ll y) {
  if (y == 0)
    return 0;
  return gcd(y, x % y);
}

int dis2(int x1, int y1, int x2, int y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
ll se = 0;
ll sume(vector<int> a, int n) {}
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ll e = 1;
  for (ll p = 2; p * p <= n; p++)
    if (n % p == 0) {
      e = 1;
      ll tmp = 0;
      while (n % p == 0) {
        n /= p;
        tmp++;
      }
      while (tmp - e >= 0) {
        tmp -= e;
        ans++;
        e++;
      }
    }
  if (n > 1)
    ans++;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll gcd(ll x, ll y) {
  if (y == 0)
    return 0;
  return gcd(y, x % y);
}

int dis2(int x1, int y1, int x2, int y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
ll se = 0;
ll sume(vector<int> a, int n) {}
int main() {
  ll n;
  cin >> n;
  int ans = 0;
  int e = 1;
  for (int p = 2; p * p <= n; p++)
    if (n % p == 0) {
      e = 1;
      int tmp = 0;
      while (n % p == 0) {
        n /= p;
        tmp++;
      }
      while (e * (e + 1) / 2 <= tmp) {
        e++;
      }
      ans += e - 1;
    }
  if (n > 1)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long

using namespace std;

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

  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      int pos = 0;
      while (n % i == 0) {
        n = n / i;
        pos++;
      }

      int x = sqrt(pos * 2);
      if (x * (x + 1) > pos * 2)
        x--;

      ans += x;
    }

  if (n > 1)
    ans++;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 1000000000000;

int pre[1000001];
int prime[1000001];
int num = 1;

struct factor {
  int x;
  int cnt;
} fac[1000001];

inline bool isprime(int x) {
  for (int i = 2; i <= sqrt(x); i++)
    if (x % i == 0)
      return false;
  return true;
}

inline void find_prime(int n) {
  for (int i = 2; i <= n; i++)
    if (isprime(i))
      prime[num++] = i;
}

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

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

  find_prime(n);

  int cnt = 1;
  for (int i = 1; i <= num; i++) {
    if (n % prime[i] == 0) {
      fac[cnt].x = prime[i];
      fac[cnt].cnt = 0;
      while (n % prime[i] == 0) {
        fac[cnt].cnt++;
        n = n / prime[i];
      }
      cnt++;
    }
    if (n == 1)
      break;
  }

  int ans = 0;
  for (int i = 1; i < cnt; i++) {
    int j = 1;
    while (j++)
      if (j * (1 + j) / 2 > fac[i].cnt)
        break;
    ans += j - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  int64_t res = 0;
  for (int64_t n = 2, end = sqrt(N); n <= end; ++n) {
    if (N < n)
      break;
    if (N % n)
      continue;
    int64_t d = 0;
    while (N % n == 0) {
      ++d;
      N /= n;
    }
    for (int64_t i = 1, end = d; i <= d; ++i) {
      if (d - i >= 0) {
        ++res;
        d -= i;
      } else {
        break;
      }
    }
  }
  if (N > 1)
    ++res;
  cout << res << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

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

int main() {
  int64_t N;
  cin >> N;
  int64_t res = 0;
  if (is_prime(N)) {
    cout << 1 << endl;
    return 0;
  }
  for (int64_t n = 2, end = N / 2; n <= end; ++n) {
    if (N < n)
      break;
    if (N % n)
      continue;
    int64_t d = 0;
    while (N % n == 0) {
      ++d;
      N /= n;
    }
    for (int64_t i = 1, end = d; i <= end; ++i) {
      if (d - i >= 0) {
        ++res;
        d -= i;
      } else {
        break;
      }
    }
  }
  cout << res << endl;

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

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

int main() {
  long long n;
  cin >> n;
  long long a[10000], m = n, j = 1;

  memset(a, 0, sizeof(a));

  for (int i = 2; i <= sqrt(n); i++) {
    if (m % i == 0) {
      while (m % i == 0) {
        m /= i;
        a[j]++;
      }
      j++;
    }
  }

  if (m > 1)
    a[j] = 1;
  int s = 0, sum = 0, ans = 0;
  for (int i = 1; i <= j; i++) {
    if (a[i] == 1) {
      ans++;
    } else {
      s = 1;
      while ((s + 1) * s / 2 <= a[i])
        s++;
      ans += s - 1;
    }
  }

  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  int a[100005], m = n;

  memset(a, 0, sizeof(a));

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

  if (m > 1)
    a[m]++;

  int s = 0, sum = 0;
  for (int i = 2; i * i <= n; i++) {
    if (a[i] == 1) {
      sum++;
    } else {
      s = 1;
      while ((s + 1) * s / 2 <= a[i])
        s++;
      sum += s - 1;
    }
  }

  cout << sum;

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

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

vector<long long> vp;
void primeFactor(long long n) {
  int C = 0;
  long long ans = 1;
  while (n % 2 == 0) {
    ans *= 2;
    vp.push_back(ans);
    n /= 2;
  }

  for (long long i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      int Count = 0;
      ans = 1;
      while (n % i == 0) {
        ans *= i;
        vp.push_back(ans);
        n /= i;
      }
    }
  }
  if (n > 2) {
    vp.push_back(n);
  }
}
int main() {
  long long n;
  cin >> n;
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  }
  primeFactor(n);
  long long Count = 0;
  sort(vp.begin(), vp.end());
  for (int i = 0; i < vp.size(); i++) {
    // cout << vp[i] << " ";
    if (n % vp[i] == 0) {
      n /= vp[i];
      Count++;
    }
  }
  cout << Count << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

vector<long long> vp;
void primeFactor(long long n) {
  int C = 0;
  long long ans = 1;
  while (n % 2 == 0) {
    ans *= 2;
    vp.push_back(ans);
    n /= 2;
  }

  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      int Count = 0;
      ans = 1;
      while (n % i == 0) {
        ans *= i;
        vp.push_back(ans);
        n /= i;
      }
    }
  }
  if (n > 2) {
    vp.push_back(n);
  }
}
int main() {
  long long n;
  cin >> n;
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  }
  primeFactor(n);
  long long Count = 0;
  sort(vp.begin(), vp.end());
  for (int i = 0; i < vp.size(); i++) {
    if (n % vp[i] == 0) {
      n /= vp[i];
      Count++;
    }
  }
  cout << Count << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mod 1000000007
#define endl '\\n'

int calc(int n) { return (int)(sqrt(2 * n + 0.25) - 0.5); }

int main() {
  ll n;
  cin >> n;
  int ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    int c = 0;
    while (n % i == 0) {
      c++;
      n /= i;
    }
    ans += calc(c);
  }
  if (n > 1)
    ans++;
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mod 1000000007
#define endl '\\n'

int calc(int n) { return (int)(sqrt(2 * n + 0.25) - 0.5); }

int main() {
  ll n;
  cin >> n;
  int ans = 0;
  for (int i = 2; i * i <= n; i++) {
    int c = 0;
    while (n % i == 0) {
      c++;
      n /= i;
    }
    ans += calc((double)c);
  }
  if (n > 1)
    ans++;
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using v = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

const ll INF = 1001001001001;

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

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

  v a;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      a.push_back(0);
      while (n % i == 0) {
        a[a.size() - 1]++;
        n /= i;
      }
    }
  }
  if (n != 1) {
    a.push_back(1);
  }

  int ans = 0;

  for (int i = 0; i < a.size(); i++) {
    double t = (sqrt(8 * a[i] + 1) - 1) / 2.0;
    ans += (int)t;
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using v = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

const ll INF = 1001001001001;

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

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

  v a;

  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      a.push_back(0);
      while (n % i == 0) {
        a[a.size() - 1]++;
        n /= i;
      }
    }
  }
  if (n != 1) {
    a.push_back(1);
  }

  int ans = 0;

  for (int i = 0; i < a.size(); i++) {
    double t = (sqrt(8 * a[i] + 1) - 1) / 2.0;
    ans += (int)t;
  }

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, m, counter = 0, flag = 0;
  long long x = 1;
  cin >> n;
  m = n;

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

  for (long long int i = 2; i * i <= m; i++) {
    if (n % i == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    cout << 1 << endl;
    return 0;
  }

  for (long long int i = 2; i * i <= m; i++) {
    x = i;
    while (n % x == 0) {
      counter++;
      n /= x;
      x *= i;
    }
    while (n % i == 0) {
      n /= i;
    }
  }
  if (n != 1) {
    counter++;
  }
  cout << counter << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, m, counter = 0, flag = 0;
  long long x = 1;
  cin >> n;
  m = n;

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

  for (long long int i = 2; i * i <= m; i++) {
    if (n % i == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    cout << 1 << endl;
    return 0;
  }

  for (long long int i = 2; i * i <= m; i++) {
    x = i;
    while (n % i == 0) {
      counter++;
      n /= x;
      x *= i;
    }
  }
  cout << counter << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

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

  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      check = 1;
      break;
    }
  }
  if (check == 0 && n != 1) {
    cout << 1 << endl;
  } else if (n == 1) {
    cout << 0 << endl;
  } else {
    long long cycle = 0;
    long long k = 1;
    long long ans = 0;
    long long a = 2;
    while (n >= a * a) {
      if (n % a == 0) {
        cycle++;
        if (2 * cycle >= k * (k + 1)) {
          ans++;
          k++;
        }
        n = n / a;
      } else {
        a++;
        cycle = 0;
        k = 1;
      }
    }

    if (n > a) {
      cout << ans + 1 << endl;
    } else if (n == a) {
      cycle++;
      if (2 * cycle >= k * (k + 1)) {
        cout << ans + 1 << endl;
      } else {
        cout << ans << endl;
      }

    } else {
      cout << ans << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

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

  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      check = 1;
      break;
    }
  }
  if (check == 0 && n != 1) {
    cout << 1 << endl;
  } else if (n == 1) {
    cout << 0 << endl;
  } else {
    long long cycle = 0;
    long long k = 1;
    long long ans = 0;
    long long a = 2;
    while (n >= a) {
      if (n % a == 0) {
        cycle++;
        if (2 * cycle >= k * (k + 1)) {
          ans++;
          k++;
        }
        n = n / a;
      } else {
        a++;
        cycle = 0;
        k = 1;
      }
    }

    cout << ans << endl;
  }
}