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

/*
  AUTHOR:SOURABH
  CREATED:31:05:20
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set                                                            \\
  tree<pii, null_type, less<pii>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i, x) for (i = 0; i < x; i++)
#define fs(i, s, x) for (i = s; i < x; i++)
#define fr(i, x) for (i = x; i >= 0; i--)
#define fit(it, s) for (it = s.begin(); it != s.end(); it++)
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  ll t, n, i, j, k, c, ans;
  t = 1;
  // cin>>t;
  W(t--) {
    cin >> n;
    ans = 0;
    for (i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        c = 0;
        W(n % i == 0) {
          n /= i;
          c++;
        }
        fs(j, 1, c + 1) {
          if (j * (j + 1) <= 2 * c)
            k = j;
          else
            break;
        }
        ans += k;
      }
    }
    if (n > 1)
      ans += 1;
    cout << ans;
  }
  return 0;
}


Error: WA

Fixed submission:

/*
  AUTHOR:SOURABH
  CREATED:31:05:20
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set                                                            \\
  tree<pii, null_type, less<pii>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i, x) for (i = 0; i < x; i++)
#define fs(i, s, x) for (i = s; i < x; i++)
#define fr(i, x) for (i = x; i >= 0; i--)
#define fit(it, s) for (it = s.begin(); it != s.end(); it++)
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

bool seive[1000001];
void build() {
  memset(seive, 0, sizeof(seive));
  seive[1] = seive[0] = 1;
  ll i, j;
  for (i = 4; i <= 1000000; i += 2)
    seive[i] = 1;
  for (i = 3; i * i <= 1000000; i += 2) {
    if (!seive[i]) {
      for (j = i * i; j <= 1000000; j += 2 * i)
        seive[j] = 1;
    }
  }
}

mll b;

ll solve(ll n) {
  if (n <= 1)
    return 0;

  ll i, j, nxt, mi, q, ans;
  bool f = 0, g = 1;
  if (!seive[n]) {
    mi = (ll)(pow(n, b[n] + 1) + .5);
    f = 1;
    q = n;
  } else
    mi = 1e15, q = 1e15;

  for (i = 2; i * i <= n; i++) {
    if (n % i == 0 && !seive[i]) {
      nxt = (ll)(pow(i, b[i] + 1) + .5);
      if (n % nxt == 0) {
        if (nxt < mi) {
          mi = nxt;
          q = i;
        }
      }
      j = n / i;
      if (!seive[j]) {
        nxt = (ll)(pow(j, b[j] + 1) + .5);
        if (n % nxt == 0) {
          if (nxt < mi) {
            mi = nxt;
            q = j;
          }
        }
      }
      f = 1;
    }
  }
  // cout<<mi<<endl;
  if (f && mi <= n) {
    b[q]++;
    ans = 1 + solve(n / mi);
  } else
    ans = 0;

  return ans;
}

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

  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  ll t, n, i, ans;
  t = 1;
  // cin>>t;
  W(t--) {
    cin >> n;
    ans = solve(n);
    cout << ans;
  }
  return 0;
}