Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
  ll x;
  cin >> x;
  return (x);
}

string ins() {
  string x;
  cin >> x;
  return (x);
}

// 素因数分解
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> mp;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1)
    mp[n]++;
  return mp;
}

// 素数判定
bool is_prime(ll n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return n != 1;
}

// 約数列挙
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.emplace_back(i);
      if (i != n / i)
        res.emplace_back(n / i);
    }
  }
  return res;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
  while (true) {
#pragma clang diagnostic pop
#endif
    ll n = inl();
    ll ans = 0;
    for (ll i = 1; i * i <= n; ++i) {
      if ((n - i) % i == 0) {
        if (n / ((n - i) / i) == n % ((n - i) / i))
          ans += (n - i) / i;
      }
    }
    cout << ans << endl;
    ////
    //        cout << "greedy~~~~~" << endl;
    //        for (int i = 1; i <= n; ++i) {
    //            if (n / i == n % i) {
    //                cout << i << ": " << n / i << endl;
    //            }
    //        }

#ifdef MY_DEBUG
  }
#endif
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
  ll x;
  cin >> x;
  return (x);
}

string ins() {
  string x;
  cin >> x;
  return (x);
}

// 素因数分解
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> mp;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1)
    mp[n]++;
  return mp;
}

// 素数判定
bool is_prime(ll n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return n != 1;
}

// 約数列挙
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.emplace_back(i);
      if (i != n / i)
        res.emplace_back(n / i);
    }
  }
  return res;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
  while (true) {
#pragma clang diagnostic pop
#endif
    ll n = inl();
    ll ans = 0;
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    for (ll i = 1; i * i <= n; ++i) {
      if ((n - i) % i == 0) {
        if (n / ((n - i) / i) == n % ((n - i) / i))
          ans += (n - i) / i;
      }
    }
    cout << ans << endl;
    ////
    //        cout << "greedy~~~~~" << endl;
    //        for (int i = 1; i <= n; ++i) {
    //            if (n / i == n % i) {
    //                cout << i << ": " << n / i << endl;
    //            }
    //        }

#ifdef MY_DEBUG
  }
#endif
  return 0;
}