Problem p03050 (C++)

Buggy submission (status: Runtime Error):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <fstream>
#include <iostream>

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

typedef long long ll;
#define tr(container, it)                                                      \
  for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end()) // O(log n)
#define contains(c, x) (find((c).begin(), (c).end(), x) != (c).end()) // O(n)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mll map<ll, ll>
#define intv(x, a, b) ((x) >= a && (x) <= b)
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(), (x).end()
// #define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;
;
const ll MOD = (ll)(1e9) + 7;
void _mod(ll &x) { x = mod(x, MOD); }
// const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

#define int ll

ll sum = 0;
void D(int n) {

  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {

      //            if (n/i == i){if(i*(i-1) > n)sum += i-1 ;}
      if (n / i == i) {
        if (n / i == n / (i - 1))
          sum += i - 1;
      }

      else
      //            {if (i*(i-1) > n)sum += i-1;
      {
        if (i != 1 && n / i == n / (i - 1))
          sum += i - 1;
        if (n / i != 1 && n / (n / i) == n / (n / i - 1))
          sum += n / i - 1;
      }
    }
  }
}
class DDivRemNumber {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    sum = 0;
    int N;
    cin >> N;
    D(N);
    cout << sum << endl;
  }
};

#undef int
int main() {
  DDivRemNumber solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <fstream>
#include <iostream>

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

typedef long long ll;
#define tr(container, it)                                                      \
  for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end()) // O(log n)
#define contains(c, x) (find((c).begin(), (c).end(), x) != (c).end()) // O(n)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mll map<ll, ll>
#define intv(x, a, b) ((x) >= a && (x) <= b)
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(), (x).end()
// #define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;
;
const ll MOD = (ll)(1e9) + 7;
void _mod(ll &x) { x = mod(x, MOD); }
// const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

#define int ll

ll sum = 0;
void D(int n) {

  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {

      //            if (n/i == i){if(i*(i-1) > n)sum += i-1 ;}
      if (n / i == i) {
        if (i != 1 && n / i == n / (i - 1))
          sum += i - 1;
      }

      else
      //            {if (i*(i-1) > n)sum += i-1;
      {
        if (i != 1 && n / i == n / (i - 1))
          sum += i - 1;
        if (n / i != 1 && n / (n / i) == n / (n / i - 1))
          sum += n / i - 1;
      }
    }
  }
}
class DDivRemNumber {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    sum = 0;
    int N;
    cin >> N;
    D(N);
    cout << sum << endl;
  }
};

#undef int
int main() {
  DDivRemNumber solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}