Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
// include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

// typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int MOD = 1000000007;

// MOD
//--------------------------------------------
#define MUL(a, b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
//--------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

// IO accelerate
//--------------------------------------------
struct InitIO {
  InitIO() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
  }
} init_io;

// main code

int main(int argc, char const *argv[]) {
  LL n;
  cin >> n;
  LL ans = 0;
  for (LL i = 1; i < min(n, (LL)500000000); i++) {
    if ((n - i) % i == 0) {
      if ((n - i) / i <= i) {
        break;
      }
      ans += (n - i) / i;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

// typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int MOD = 1000000007;

// MOD
//--------------------------------------------
#define MUL(a, b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
//--------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

// IO accelerate
//--------------------------------------------
struct InitIO {
  InitIO() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
  }
} init_io;

// main code

int main(int argc, char const *argv[]) {
  LL n;
  cin >> n;
  LL ans = 0;
  for (LL i = 1; i < min(n, (LL)10000000); i++) {
    if ((n - i) % i == 0) {
      if ((n - i) / i <= i) {
        break;
      }
      ans += (n - i) / i;
    }
  }
  cout << ans << endl;
  return 0;
}