Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define inf (ll)1e9

#define debugone(x)                                                            \
  cout << #x << " " << x << "\n";                                              \
  cout.flush();
#define debugtwo(x)                                                            \
  cout << #x << "-------------"                                                \
       << "\n";                                                                \
  for (auto &it : x)                                                           \
    cout << it << " ";                                                         \
  cout << "\n";                                                                \
  cout.flush();
#define debugthree(x, i, j)                                                    \
  cout << #x << "------------"                                                 \
       << "\n";                                                                \
  cout << "from " << i << " to " << j << "\n";                                 \
  for (ll k = i; k <= j; k++)                                                  \
    cout << x[k] << " ";                                                       \
  cout << "\n";                                                                \
  cout.flush();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll n;
  cin >> n;
  ll sqrtn = sqrt(n);

  // N = (m + 1) (N/m)
  ll res = 0;
  for (ll i = 1; i <= sqrtn; i++) {
    if (n % i == 0) {
      ll m = n / i - 1;
      if (n % m == n / m) {
        res += m;
      }
    }
  }

  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define inf (ll)1e9

#define debugone(x)                                                            \
  cout << #x << " " << x << "\n";                                              \
  cout.flush();
#define debugtwo(x)                                                            \
  cout << #x << "-------------"                                                \
       << "\n";                                                                \
  for (auto &it : x)                                                           \
    cout << it << " ";                                                         \
  cout << "\n";                                                                \
  cout.flush();
#define debugthree(x, i, j)                                                    \
  cout << #x << "------------"                                                 \
       << "\n";                                                                \
  cout << "from " << i << " to " << j << "\n";                                 \
  for (ll k = i; k <= j; k++)                                                  \
    cout << x[k] << " ";                                                       \
  cout << "\n";                                                                \
  cout.flush();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll n;
  cin >> n;
  ll sqrtn = sqrt(n);

  // N = (m + 1) (N/m)
  ll res = 0;
  for (ll i = 1; i <= sqrtn; i++) {
    if (n % i == 0) {
      ll m = n / i - 1;
      if (m == 0)
        continue;
      if (n % m == n / m) {
        res += m;
      }
    }
  }

  cout << res << endl;
}