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

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define lb lower_bound
#define ub upper_bound
#define owo                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                              \\
  for (long blockTime = 0;                                                     \\
       (blockTime == 0 ? (blockTime = clock()) != 0 : false);                  \\
       debug("%s time : %.4fs\\n", d,                                           \\
             (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
ll prime[1000005];
ll phi[1000005];
vector<ll> p;
void sieve(int n) {
  prime[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (prime[i] == 0) {
      prime[i] = i;
      p.pb(i);
    }
    for (int j = 0; j < (int)(p.size()) && p[j] <= prime[i] && i * p[j] <= n;
         j++) {
      prime[i * p[j]] = p[j];
    }
  }
}
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  sieve(n);
  for (int i = 1; i < n; i++) {
    ll num = 1;
    int j = i;
    while (j != 1) {
      ll cnt = 0;
      int p = prime[j];
      while (j % p == 0) {
        j /= p;
        cnt++;
      }
      num *= (cnt + 1);
    }
    ans += num;
  }
  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define lb lower_bound
#define ub upper_bound
#define owo                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                              \\
  for (long blockTime = 0;                                                     \\
       (blockTime == 0 ? (blockTime = clock()) != 0 : false);                  \\
       debug("%s time : %.4fs\\n", d,                                           \\
             (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
ll prime[100001];
ll phi[1000001];
vector<ll> p;
void sieve(int n) {
  prime[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (prime[i] == 0) {
      prime[i] = i;
      p.pb(i);
    }
    for (int j = 0; j < (int)(p.size()) && p[j] <= prime[i] && i * p[j] <= n;
         j++) {
      prime[i * p[j]] = p[j];
    }
  }
}
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  sieve(n);
  for (int i = 1; i < n; i++) {
    ll num = 1;
    int j = i;
    while (j != 1) {
      ll cnt = 0;
      int p = prime[j];
      while (j % p == 0) {
        j /= p;
        cnt++;
      }
      num *= (cnt + 1);
    }
    ans += num;
  }
  cout << ans << '\\n';
}