Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#if 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;

#define LOADVEC(type, name, N)                                                 \
  std::vector<type> name(N);                                                   \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name[nnn];                                                          \
  }

#define LOADVEC2(type, name0, name1, N)                                        \
  std::vector<type> name0(N), name1(N);                                        \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name0[nnn];                                                         \
    cin >> name1[nnn];                                                         \
  }

#define LOADVEC3(type, name0, name1, name2, N)                                 \
  std::vector<type> name0(N), name1(N), name2(N);                              \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name0[nnn];                                                         \
    cin >> name1[nnn];                                                         \
    cin >> name2[nnn];                                                         \
  }

#define LOAD(type, name)                                                       \
  type name;                                                                   \
  cin >> name;

void proc();

signed main() {
  ios::sync_with_stdio(false);
  proc();
  return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/

void proc() {
  LOAD(int, N);
  if (N == 2) {
    cout << 0 << endl;
    return;
  }
  int res = 0;
  for (int a = 1;; ++a) {
    if (N % a != 0)
      continue;
    int m = N / a - 1;
    if (a >= m)
      break;
    res += m;
  }
  cout << res << endl;
}

#endif


Fixed submission:
#if 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;

#define LOADVEC(type, name, N)                                                 \
  std::vector<type> name(N);                                                   \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name[nnn];                                                          \
  }

#define LOADVEC2(type, name0, name1, N)                                        \
  std::vector<type> name0(N), name1(N);                                        \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name0[nnn];                                                         \
    cin >> name1[nnn];                                                         \
  }

#define LOADVEC3(type, name0, name1, name2, N)                                 \
  std::vector<type> name0(N), name1(N), name2(N);                              \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name0[nnn];                                                         \
    cin >> name1[nnn];                                                         \
    cin >> name2[nnn];                                                         \
  }

#define LOAD(type, name)                                                       \
  type name;                                                                   \
  cin >> name;

void proc();

signed main() {
  ios::sync_with_stdio(false);
  proc();
  return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/

void proc() {
  LOAD(int, N);
  if (N == 2) {
    cout << 0 << endl;
    return;
  }
  int res = 0;
  for (int a = 1;; ++a) {
    double m_ = 1.0 * N / a - 1;
    if (a >= m_)
      break;
    if (N % a != 0)
      continue;
    int m = N / a - 1;
    if (a >= m)
      break;
    res += m;
  }
  cout << res << endl;
}

#endif