Problem p02660 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = 998244353;
#define ll long long
#define ld long double
#define pb push_back
#define Dracarys                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define all(x) x.begin(), x.end()

ll po(ll x, ll y, ll md = mod) {
  ll res = 1;
  x %= md;

  while (y) {
    if (y & 1) {
      res = (res * x) % md;
    }
    y >>= 1;
    x = (x * x) % md;
  }
  return res;
}

bitset<1000000 + 5> prime;

void sieve(ll n) {
  prime.flip();
  prime[1] = 0;
  for (ll i = 2; i <= n; i++) {
    if (prime[i]) {
      for (ll j = i * i; j <= n; j += i) {
        prime[j] = 0;
      }
    }
  }
}

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

  sieve(1000000 + 3);

  if (n == 1) {
    cout << "0\\n";
    return;
  }
  vector<ll> pp, give;
  ll sz = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    ll f1, f2;
    f1 = i;
    f2 = n / i;
    if (n % f1 == 0) {
      ll temp = n;
      if (prime[f1]) {
        ll ti = 0;
        while (temp % f1 == 0) {
          ti++;
          temp /= f1;
        }
        // check
        pp.pb(f1);
        give.pb(ti);
        sz++;
      }
    }
  }

  ll cnt = 0;
  for (ll i = 0; i < sz; i++) {
    ll mx = give[i];
    ll low = 1, high = 1e8, inter = 0;
    while (low <= high) {
      ll mid = low + (high - low) / 2;
      ll zz = (mid * (mid + 1)) / 2;
      if (zz <= mx) {
        inter = mid;
        low = mid + 1;
      } else
        high = mid - 1;
    }
    cnt += inter;
  }
  ll rem = n;

  for (ll i = 0; i < sz; i++) {
    rem /= (pow(pp[i], give[i]));
  }

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

  if (rem == 1) {
    flag = false;
  }

  if (flag) {
    cnt++;
  }

  cout << cnt << "\\n";
}

int main() {

  Dracarys

      ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:

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

const int mod = 998244353;
#define ll long long
#define ld long double
#define pb push_back
#define Dracarys                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define all(x) x.begin(), x.end()

ll po(ll x, ll y, ll md = mod) {
  ll res = 1;
  x %= md;

  while (y) {
    if (y & 1) {
      res = (res * x) % md;
    }
    y >>= 1;
    x = (x * x) % md;
  }
  return res;
}

bitset<1000000 + 5> prime;

void sieve(ll n) {
  prime.flip();
  prime[1] = 0;
  for (ll i = 2; i <= n; i++) {
    if (prime[i]) {
      for (ll j = i * i; j <= n; j += i) {
        prime[j] = 0;
      }
    }
  }
}

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

  sieve(1000000 + 3);

  if (n == 1) {
    cout << "0\\n";
    return;
  }
  vector<ll> pp, give;
  ll sz = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    ll f1, f2;
    f1 = i;
    f2 = n / i;
    if (n % f1 == 0) {
      ll temp = n;
      if (prime[f1]) {
        ll ti = 0;
        while (temp % f1 == 0) {
          ti++;
          temp /= f1;
        }
        // check
        pp.pb(f1);
        give.pb(ti);
        sz++;
      }
    }
  }

  ll cnt = 0;
  for (ll i = 0; i < sz; i++) {
    ll mx = give[i];
    ll low = 1, high = 1e8, inter = 0;
    while (low <= high) {
      ll mid = low + (high - low) / 2;
      ll zz = (mid * (mid + 1)) / 2;
      if (zz <= mx) {
        inter = mid;
        low = mid + 1;
      } else
        high = mid - 1;
    }
    cnt += inter;
  }
  ll rem = n;
  for (ll i = 1; i <= n; i++) {
    rem /= (pow(pp[i], give[i]));
  }

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

  if (flag) {
    cnt++;
  }

  cout << cnt << "\\n";
}

int main() {

  Dracarys

      ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}