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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++)
#define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++)
#define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++)
#define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++)
#define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--)
#define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--)
#define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--)
#define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--)
#define iter(i, it) for (auto &(i) : (it))

template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> m) {
  cout << "(" << m.first << ", " << m.second << ")";
  return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const map<T, U> m) {
  ll c = 0;
  cout << "{ ";
  iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  cout << "{ ";
  rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const list<T> &v) {
  ll c = 0;
  cout << "{ ";
  iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}

#define MAX 10000001
vector<ll> hurui(MAX);

void prepare() {
  hurui[1] = 1;
  rep2(i, 2, MAX) {
    if (hurui[i] == 0) {
      for (ll j = i; j < MAX; j += i)
        hurui[j] = i;
    }
  }
}

void factor(ll n, map<ll, ll> &factors) {
  if (n == 1) {
    factors[1]++;
    return;
  }
  while (true) {
    ll temp = hurui[n];
    factors[temp]++;
    if (temp == n)
      break;
    n = n / temp;
  }
}

int main(void) {
  ll N;
  vector<int> a;
  prepare();
  ll ans = 1;
  cin >> N;
  repi2(i, 2, N) {
    map<ll, ll> m;
    factor(i, m);
    ll temp = 1;
    iter(j, m) { temp *= j.second + 1; }
    // cout << temp << endl;
    ans += i * temp;
  }
  cout << ans << endl;
  // map<ll, ll> m;
  // factor(100, m);
  // cout << m << endl;
  return 0;
}


Error: WA

Fixed submission:

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++)
#define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++)
#define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++)
#define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++)
#define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--)
#define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--)
#define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--)
#define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--)
#define iter(i, it) for (auto &(i) : (it))

template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> m) {
  cout << "(" << m.first << ", " << m.second << ")";
  return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const map<T, U> m) {
  ll c = 0;
  cout << "{ ";
  iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  cout << "{ ";
  rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const list<T> &v) {
  ll c = 0;
  cout << "{ ";
  iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}

#define MAX 100 // 10000001
vector<ll> hurui(MAX);

void prepare() {
  hurui[1] = 1;
  rep2(i, 2, MAX) {
    if (hurui[i] == 0) {
      for (ll j = i; j < MAX; j += i)
        hurui[j] = i;
    }
  }
}

void factor(ll n, map<ll, ll> &factors) {
  if (n == 1) {
    factors[1]++;
    return;
  }
  while (true) {
    ll temp = hurui[n];
    if (temp == n)
      break;
    factors[temp] = n / temp;
    cout << n / temp << endl;
    n = temp;
  }
}

int main(void) {
  ll N;
  vector<int> a;
  prepare();
  cin >> N;
  ll ans = 0;
  repi2(i, 1, N) {
    map<ll, ll> m;
    factor(i, m);
    ll temp = 1;
    iter(j, m) { temp *= j.second; }
    ans += i * temp;
  }
  cout << ans << endl;
  return 0;
}