Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for (ll i = a; i < n; i++)

#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#pragma comment(linker, "/STACK:8809999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<ll, pll> pllp;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ll atcmod = 998244353;
const ld eps = 1e-9;
const ll settled = 400007;

vector<pll> pe;
ll globe;

ll pussy_hacker(ll m, ll i) {
  ll ans = 0;
  forn(j, 0, pe[i].second + 1) {
    if (i + 1 < pe.size())
      ans += pussy_hacker(m, i + 1);
    else if (m > 1 && (m - 1) > globe / (m - 1))
      ans += m - 1;
    m *= pe[i].first;
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
#ifndef overlord
  /*freopen("capitals.in", "r", stdin);
  freopen("capitals.out", "w", stdout);*/
#else
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  globe = n;
  forn(i, 2, (ll)sqrt((ld)n) + 1) {
    if (n % i == 0) {
      pe.push_back({i, 0});
      while (n % i == 0) {
        pe.back().second++;
        n /= i;
      }
    }

    if (n == 1)
      break;
  }

  if (n > 1)
    pe.push_back({n, 1});

  cout << pussy_hacker(1, 0);
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for (ll i = a; i < n; i++)

#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#pragma comment(linker, "/STACK:8809999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<ll, pll> pllp;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ll atcmod = 998244353;
const ld eps = 1e-9;
const ll settled = 400007;

vector<pll> pe;
ll globe;

ll pussy_hacker(ll m, ll i) {
  ll ans = 0;
  forn(j, 0, pe[i].second + 1) {
    if (i + 1 < pe.size())
      ans += pussy_hacker(m, i + 1);
    else if (m > 1 && (m - 1) > globe / (m - 1))
      ans += m - 1;
    m *= pe[i].first;
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
#ifndef overlord
  /*freopen("capitals.in", "r", stdin);
  freopen("capitals.out", "w", stdout);*/
#else
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  globe = n;
  if (n == 1) {
    cout << 0;
    return 0;
  }

  forn(i, 2, (ll)sqrt((ld)n) + 1) {
    if (n % i == 0) {
      pe.push_back({i, 0});
      while (n % i == 0) {
        pe.back().second++;
        n /= i;
      }
    }

    if (n == 1)
      break;
  }

  if (n > 1)
    pe.push_back({n, 1});

  cout << pussy_hacker(1, 0);
  return 0;
}