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

#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
#define yy cout << "YES\\n"
#define nn cout << "NO\\n"
#define rt return
#define ct continue
#define br break
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mmod 1000000007
#define pmod 998244353
using namespace std;
int gcd(int a, int b) {
  while (b)
    b ^= a ^= b ^= a %= b;
  return a;
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int bigmod(int b, int p, int m) {
  int ans = 1;
  b %= m;
  if (!b)
    return 0;
  while (p) {
    if (p & 1)
      ans = (ans * b) % m;
    p >>= 1;
    b = (b * b) % m;
  }
  return ans;
}
int f[1000001];
void recur() {
  f[1] = 1;
  for (int i = 1; i < 1000001; i++)
    f[i] = i;
  for (int i = 4; i < 1000001; i += 2)
    f[i] = 2;
  for (int i = 3; i * i < 1000001; i++) {
    if (f[i] == i) {
      for (int j = i * i; j < 1000001; j += i) {
        if (f[j] == j)
          f[j] = i;
      }
    }
  }
}
int fac(int n) {
  if (n == 1)
    return 1;
  int ans = 1;
  int d = f[n], c = 1, j = n / f[n];
  while (j != 1) {
    if (f[j] == d)
      c++;
    else {
      d = f[j];
      ans *= (c + 1);
      c = 1;
    }
    j /= f[j];
  }
  return ans * (c + 1);
}
void solve() {
  recur();
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += fac(n - i);
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}

Error: WA

Fixed submission:

#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
#define yy cout << "YES\\n"
#define nn cout << "NO\\n"
#define rt return
#define ct continue
#define br break
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mmod 1000000007
#define pmod 998244353
using namespace std;
int gcd(int a, int b) {
  while (b)
    b ^= a ^= b ^= a %= b;
  return a;
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int bigmod(int b, int p, int m) {
  int ans = 1;
  b %= m;
  if (!b)
    return 0;
  while (p) {
    if (p & 1)
      ans = (ans * b) % m;
    p >>= 1;
    b = (b * b) % m;
  }
  return ans;
}
int f[100001];
void recur() {
  f[1] = 1;
  for (int i = 1; i < 100001; i++)
    f[i] = i;
  for (int i = 4; i < 100001; i += 2)
    f[i] = 2;
  for (int i = 3; i * i < 100001; i++) {
    if (f[i] == i) {
      for (int j = i * i; j < 100001; j += i) {
        if (f[j] == j)
          f[j] = i;
      }
    }
  }
}
int fac(int n) {
  if (n == 1)
    return 1;
  int ans = 1;
  int d = f[n], c = 1, j = n / f[n];
  while (j != 1) {
    if (f[j] == d)
      c++;
    else {
      d = f[j];
      ans *= (c + 1);
      c = 1;
    }
    j /= f[j];
  }
  return ans * (c + 1);
}
void solve() {
  recur();
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += fac(n - i);
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}