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

#pragma GCC optimize(2)
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define File(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout);
#define re register
#define ri re int
#define gtch()                                                                 \\
  (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)     \\
       ? EOF                                                                   \\
       : *p1++)
#define For(i, a, b) for (ri i = a; i <= b; ++i)
#define iFor(i, a, b) for (ri i = a; i >= b; --i)
using namespace std;
typedef long long ll;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline ll fr() {
  re char ch = getchar();
  re ll res = 0;
  int bl = 0;
  while (!isdigit(ch))
    bl = (ch == '-'), ch = getchar();
  while (isdigit(ch))
    res = (res << 1) + (res << 3) + ch - '0', ch = getchar();
  return bl ? -res : res;
}
const int MAXN = 1e7;
int mf[MAXN];
ll prime[MAXN], tot;
ll d[MAXN], cnt[MAXN];
int n;
inline void sieve() {
  d[1] = 1;
  for (ri i = 2; i <= n; ++i) {
    if (!mf[i]) {
      mf[i] = i, prime[++tot] = i, d[i] = 2, cnt[i] = 1;
    }
    //		cout<<i<<" "<<d[i]<<" "<<cnt[i]<<"\\n";
    for (ri j = 1; j <= tot; ++j) {
      ri p = prime[j], t = i * p;
      if (t > n)
        break;
      mf[t] = p;
      if (p == mf[i]) {
        cnt[t] = cnt[i] + 1, d[t] = d[i] / (cnt[i] + 1) * (cnt[i] + 2);
        break;
      }
      cnt[t] = 1, d[t] = d[i] * 2;
    }
  }
}
signed main() {
  //	File("temp")
  n = fr();
  sieve();
  ll ans = 0;
  for (ri i = 1; i < n; ++i)
    ans += d[i];
  cout << ans;
  return 0;
}

Error: -11

Fixed submission:

#pragma GCC optimize(2)
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define File(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout);
#define re register
#define ri re int
#define gtch()                                                                 \\
  (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)     \\
       ? EOF                                                                   \\
       : *p1++)
#define For(i, a, b) for (ri i = a; i <= b; ++i)
#define iFor(i, a, b) for (ri i = a; i >= b; --i)
using namespace std;
typedef long long ll;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline ll fr() {
  re char ch = getchar();
  re ll res = 0;
  int bl = 0;
  while (!isdigit(ch))
    bl = (ch == '-'), ch = getchar();
  while (isdigit(ch))
    res = (res << 1) + (res << 3) + ch - '0', ch = getchar();
  return bl ? -res : res;
}
const int MAXN = 1e7;
int mf[MAXN];
ll prime[MAXN], tot;
ll d[MAXN], cnt[MAXN];
int n;
inline void sieve() {
  d[1] = 1;
  for (ri i = 2; i <= n; ++i) {
    if (!mf[i]) {
      mf[i] = i, prime[++tot] = i, d[i] = 2, cnt[i] = 1;
    }
    //		cout<<i<<" "<<d[i]<<" "<<cnt[i]<<"\\n";
    for (ri j = 1; j <= tot; ++j) {
      ri p = prime[j], t = i * p;
      mf[t] = p;
      if (p == mf[i]) {
        cnt[t] = cnt[i] + 1, d[t] = d[i] / (cnt[i] + 1) * (cnt[i] + 2);
        break;
      }
      cnt[t] = 1, d[t] = d[i] * 2;
    }
  }
}
signed main() {
  //	File("temp")
  n = fr();
  sieve();
  ll ans = 0;
  for (ri i = 1; i < n; ++i)
    ans += d[i];
  cout << ans;
  return 0;
}