prithivMLmods/Coder-Stat huggingface dataset:
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long qmax = sqrt(N);
  long long sum = 0;
  for (long long q = 1; q < qmax + 1; q++) {
    if (N % q == 0) {
      long long m = N / q - 1;
      if ((N / m) == (N % m)) {
        sum = sum + m;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long qmax = sqrt(N);
  long long sum = 0;
  for (long long q = 1; q < qmax + 1; q++) {
    if (N % q == 0) {
      long long m = N / q - 1;
      if (m != 0) {
        if ((N / m) == (N % m)) {
          sum = sum + m;
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n, ans = 0;
  scanf("%lld", &n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / (i - 1) == n % (i - 1))
        ans += i - 1;
      if (n / i != i && n / (n / i - 1) == n % (n / i - 1))
        ans += n / i - 1;
    }
  }
  if (n / (n - 1) == n % (n - 1))
    ans += n - 1;
  printf("%lld\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n, ans = 0;
  scanf("%lld", &n);
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / (i - 1) == n % (i - 1))
        ans += i - 1;
      if (n / i != i && n / (n / i - 1) == n % (n / i - 1))
        ans += n / i - 1;
    }
  }
  if (n / (n - 1) == n % (n - 1))
    ans += n - 1;
  printf("%lld\n", ans);
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {

  long long int n;
  cin >> n;

  long long int ans = 0;

  for (long long int i = 1; i * i <= n; i++) {

    if ((n - i) % i != 0)
      continue;
    long long int cnt = (n - i) / i;
    if (n / cnt != n % cnt)
      continue;
    ans += cnt;
  }

  cout << ans << endl;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {

  long long int n;
  cin >> n;

  long long int ans = 0;

  for (long long int i = 1; i * i <= n; i++) {

    if ((n - i) % i != 0)
      continue;
    long long int cnt = (n - i) / i;
    if (cnt == 0)
      continue;
    if (n / cnt != n % cnt)
      continue;
    ans += cnt;
  }

  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  uint64_t sum = 0;
  // for (int64_t d = 1; d <= N; ++d) {
  // 	if (N/d == N%d) {
  // 		cout << d << " " << N/d << endl;
  // 	}
  // }
  for (int64_t r = 1; r * r <= N; ++r) {
    if (N % r == 0) {
      int64_t test = N / r - 1;
      if (N / test == N % test) {
        // cout << test << endl;
        sum += test;
      }
      // cout <<  << endl;
    }
    // int64_t d = N/r, dd = d-r;
    // cout << "ee " << d << " " << dd << endl;
    // if (dd < 0) continue;
    // if (N%dd == N/dd) {
    // 	cout << dd << " " << N/dd << endl;
    // 	// cout << d
    // }
  }
  cout << sum << endl;
  // cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  uint64_t sum = 0;
  // for (int64_t d = 1; d <= N; ++d) {
  // 	if (N/d == N%d) {
  // 		cout << d << " " << N/d << endl;
  // 	}
  // }
  for (int64_t r = 1; r * r <= N; ++r) {
    if (N % r == 0) {
      int64_t test = N / r - 1;
      if (test <= 0)
        continue;
      if (N / test == N % test) {
        // cout << test << endl;
        sum += test;
      }
      // cout <<  << endl;
    }
    // int64_t d = N/r, dd = d-r;
    // cout << "ee " << d << " " << dd << endl;
    // if (dd < 0) continue;
    // if (N%dd == N/dd) {
    // 	cout << dd << " " << N/dd << endl;
    // 	// cout << d
    // }
  }
  cout << sum << endl;
  // cout << sum << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
using ll = long long;
using namespace std;
int main() {
  ll n;
  cin >> n;
  // n以下のうち、商とあまりが等しくなるもの
  // a*m+m=n (m<a)
  // aで全探索
  ll ans = 0;
  for (ll i = 1; i < sqrtl(n) + 1; i++) {
    ll tmp = (n - i) / i;
    if (n / tmp == n % tmp) {
      ans += tmp;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
using ll = long long;
using namespace std;
int main() {
  ll n;
  cin >> n;
  // n以下のうち、商とあまりが等しくなるもの
  // a*m+m=n (m<a)
  // aで全探索
  ll ans = 0;
  for (ll i = 1; i < sqrtl(n); i++) {
    ll tmp = (n - i) / i;
    if (n / tmp == n % tmp) {
      ans += tmp;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << setprecision(8) << setiosflags(ios::fixed);

  ll n;
  cin >> n;

  ll sum = 0;
  for (ll k = 1; k * k <= n; ++k) {
    ll km = n - k;
    if (km % k != 0)
      continue;

    ll m = km / k;
    ll div = n / m, am = n % m;
    if (div == k && am == k)
      sum += m;
  }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << setprecision(8) << setiosflags(ios::fixed);

  ll n;
  cin >> n;

  ll sum = 0;
  for (ll k = 1; k * k <= n; ++k) {
    ll km = n - k;
    if (km % k != 0)
      continue;

    ll m = km / k;
    if (m <= 0)
      continue;
    ll div = n / m, am = n % m;
    if (div == k && am == k)
      sum += m;
  }

  cout << sum << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
  v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n, size_t o = 0) {
  v = vector<T>(n + o);
  for (size_t i = o; i < n + o; ++i)
    cin >> v[i];
}
template <class T> void read_n(T a[], size_t n, size_t o = 0) {
  for (size_t i = o; i < n + o; ++i)
    cin >> a[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs

template <class F> i64 bisect(i64 l, i64 r, F f) { // (l, r]
  if (r - l <= 1)
    return r;
  i64 m = l + (r - l) / 2;
  return f(m) ? bisect(l, m, f) : bisect(m, r, f);
}

i64 n;
int main() {
  cin >> n;
  i64 sn = sqrt(double(n)) + 1;
  i64 ans = 0;
  for (i64 y = 1; y <= sn; ++y) {
    i64 l = n / (y + 1), r = n / y;
    // l < x <= r

    i64 z = bisect(l, r, [=](i64 x) { return y >= n % x; });
    // cerr << y << '\t' << l << '\t' << r << '\t' << z << endl;
    if (y == n % z)
      ans += z;
  }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
  v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n, size_t o = 0) {
  v = vector<T>(n + o);
  for (size_t i = o; i < n + o; ++i)
    cin >> v[i];
}
template <class T> void read_n(T a[], size_t n, size_t o = 0) {
  for (size_t i = o; i < n + o; ++i)
    cin >> a[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs

template <class F> i64 bisect(i64 l, i64 r, F f) { // (l, r]
  if (r - l <= 1)
    return r;
  i64 m = l + (r - l) / 2;
  return f(m) ? bisect(l, m, f) : bisect(m, r, f);
}

i64 n;
int main() {
  cin >> n;
  i64 sn = sqrt(double(n)) + 1;
  i64 ans = 0;
  for (i64 y = 1; y <= sn; ++y) {
    i64 l = n / (y + 1), r = n / y;
    // l < x <= r
    //
    if (r == 0)
      continue;

    i64 z = bisect(l, r, [=](i64 x) { return y >= n % x; });
    // cerr << y << '\t' << l << '\t' << r << '\t' << z << endl;
    if (y == n % z)
      ans += z;
  }
  cout << ans << '\n';
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; // x軸方向への変位
ll dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; // y軸方向への変位

ll n;
string a;
vector<string> ans;
string c = "abcdefghijklm";

int main(void) {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= sqrt(n); i++) {
    ll check = n - i;
    ll b = check / i;
    if (check % i == 0 && n % b == i) {
      ans += check / i;
      //  cout << i << " " << n%b<< endl;
    }
  }
  // cout << 2499687339915-2499686339916 << endl;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; // x軸方向への変位
ll dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; // y軸方向への変位

ll n;
string a;
vector<string> ans;
string c = "abcdefghijklm";

int main(void) {
  ll n;
  cin >> n;
  ll ans = 0;
  if (n > 1) {
    for (ll i = 1; i <= sqrt(n); i++) {
      ll check = n - i;
      ll b = check / i;
      if (check % i == 0 && n % b == i)
        ans += check / i;
    }
  }
  // cout << 2499687339915-2499686339916 << endl;
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i > 1) {
        if (n / (i - 1) == n % (i - 1)) {
          ans += i - 1;
        }
      }
      long long d = n / i - 1;
      if (n / d == n % d) {
        ans += d;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i > 1) {
        if (n / (i - 1) == n % (i - 1)) {
          ans += i - 1;
        }
      }
      long long d = n / i - 1;
      if (d > 0) {
        if (n / d == n % d) {
          ans += d;
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;

int main() {
  int64_t N, answer = 0;
  cin >> N;
  for (int64_t i = 1; i < N; i++) {
    if (N % i == N / i)
      answer += i;
  }
  cout << answer;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;

int main() {
  int64_t N, answer = 0;
  cin >> N;
  for (int64_t i = 1; i * i < N; i++) {
    if (N % i == 0 && i < (N / i) - 1)
      answer += (N / i) - 1;
  }
  cout << answer;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int N;
int ans = 0;

signed main(void) {
  cin >> N;

  for (int p = 1; p * p <= N; p++) {
    if (N % p == 0) { // 約数
      int m_plus_one = N / p;
      int m = m_plus_one - 1;
      if (N % m == N / m)
        ans += m;
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int N;
int ans = 0;

signed main(void) {
  cin >> N;

  for (int p = 1; p * p <= N; p++) {
    if (N % p == 0) { // 約数
      int m_plus_one = N / p;
      int m = m_plus_one - 1;
      if (m == 0)
        continue;
      if (N % m == N / m)
        ans += m;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03050 (C++)

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

int main() {
  long long N, ans = 0;
  cin >> N;
  for (int p = 1; p * (p + 1) < N; p++) {
    if (N % p == 0)
      ans += N / p - 1;
  }
  cout << ans << endl;
}

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

int main() {
  long long N, ans = 0;
  cin >> N;
  for (int p = 1; (N - p) / p > p; p++) {
    if (N % p == 0)
      ans += N / p - 1;
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x)                                                                \
  rep(i, x.size()) {                                                           \
    cout << x[i] << " ";                                                       \
    cout << endl;                                                              \
  }
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
  ll n;
  cin >> n;
  set<ll> st;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      st.insert(i);
      st.insert(n / i);
    }
  }
  ll ans = 0;
  for (ll x : st) {
    ll m = n / x - 1;
    if (n / m == n % m)
      ans += m;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x)                                                                \
  rep(i, x.size()) {                                                           \
    cout << x[i] << " ";                                                       \
    cout << endl;                                                              \
  }
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
  ll n;
  cin >> n;
  set<ll> st;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      st.insert(i);
      st.insert(n / i);
    }
  }
  ll ans = 0;
  for (ll x : st) {
    ll m = n / x - 1;
    if (m == 0)
      continue;
    if (n / m == n % m)
      ans += m;
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

set<ll> a;
int main() {
  ll n;
  cin >> n;
  ll m = sqrt(n);
  for (ll i = 1; i <= m; i++) {
    if (n % i != 0) {
      continue;
    }
    ll now = n / i;
    ll ma = max(now, i);
    ma--;
    ll mi = min(now, i);
    if (n / ma == mi) {
      a.insert(ma);
    }
  }
  ll ans = 0;
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ans += *itr;
  }
  cout << ans;
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

set<ll> a;
int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  ll m = sqrt(n);
  for (ll i = 1; i <= m; i++) {
    if (n % i != 0) {
      continue;
    }
    ll now = n / i;
    ll ma = max(now, i);
    ma--;
    ll mi = min(now, i);
    if (n / ma == mi) {
      a.insert(ma);
    }
  }
  ll ans = 0;
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ans += *itr;
  }
  cout << ans;
  // your code goes here
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      long long a = i, b = N / i;
      if (a - 1 > 0 && N % (a - 1) == (N / (a - 1)))
        ans += a - 1;
      if (N % (b - 1) == N / (b - 1))
        ans += b - 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      long long a = i, b = N / i;
      if (a - 1 > 0 && N % (a - 1) == (N / (a - 1)))
        ans += a - 1;
      if (b != a && b - 1 > 0 && N % (b - 1) == N / (b - 1))
        ans += b - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define st(arr, a) memset(arr, a, sizeof arr)
#define nl cout << endl
#define real signed
#define endl '\n'
#define bitcount(x) __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define rfor(i, a, b) for (int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define X first
#define Y second
#define N 314159
#define vi vector<int>
#define v vector

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  set<int> dc;
  int sum = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      dc.insert(i);
      dc.insert(n / i);
    }
  }
  dc.insert(n);
  for (auto i : dc) {
    int x = i * (n % (i - 1));
    if (x == n)
      sum += i - 1;
  }
  cout << sum;

  return 0;
}

//       g++ -g c.cpp ; ./a.exe

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define st(arr, a) memset(arr, a, sizeof arr)
#define nl cout << endl
#define real signed
#define endl '\n'
#define bitcount(x) __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define rfor(i, a, b) for (int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define X first
#define Y second
#define N 314159
#define vi vector<int>
#define v vector

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  set<int> dc;
  int sum = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      dc.insert(i);
      dc.insert(n / i);
    }
  }
  if (n != 1)
    dc.insert(n);
  for (auto i : dc) {
    int x = i * (n % (i - 1));
    if (x == n)
      sum += i - 1;
  }
  cout << sum;

  return 0;
}

//       g++ -g c.cpp ; ./a.exe
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll a = 1; a <= n; a++) {
    if (n % a == 0) {
      ll m = n / a - 1;
      if (m <= a)
        break;
      if (m >= 1)
        ans += m;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll a = 1; a * a <= n; a++) {
    if (n % a == 0) {
      ll m = n / a - 1;
      if (m <= a)
        break;
      if (m >= 1)
        ans += m;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define rep1(i, n) for (auto i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;

int main() {
  ll n;
  cin >> n;

  ll sum = 0;
  rep1(k, n) {
    if (n % k == 0) {
      ll m = (n / k) - 1;
      if (m <= 0)
        break;
      if (n % m != k)
        break;
      sum += m;
    }
  }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define rep1(i, n) for (auto i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;

int main() {
  ll n;
  cin >> n;

  ll sum = 0;
  ll sq = n / (ll)sqrt(n) + 5;
  rep1(k, sq) {
    if (n % k == 0) {
      ll m = (n / k) - 1;
      if (m <= 0)
        break;
      if (n % m != k)
        break;
      sum += m;
    }
  }

  cout << sum << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include"testlib.h"

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;

int main(int argc, char *argv[]) {

  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  ll n;
  cin >> n;

  ll sq = sqrtl(n);

  while (sq * sq < n)
    sq++;
  while (sq * sq > n)
    sq--;

  // ll sum = 0;
  // for(int i = 1; i <= n; ++i){
  //     if(n / i == n % i) sum += i;
  // }

  // cout << sum << endl;

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

  cout << res << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #include"testlib.h"

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;

int main(int argc, char *argv[]) {

  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  ll n;
  cin >> n;

  ll sq = sqrtl(n);

  while (sq * sq < n)
    sq++;
  while (sq * sq > n)
    sq--;

  // ll sum = 0;
  // for(int i = 1; i <= n; ++i){
  //     if(n / i == n % i) sum += i;
  // }

  // cout << sum << endl;

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

  cout << res << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;

  vector<ll> d;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      d.push_back(i);
      if (i * i != n) {
        d.push_back(n / i);
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < d.size(); ++i) {
    if (n % (d[i] - 1) == n / (d[i] - 1)) {
      ans += d[i] - 1;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;

  vector<ll> d;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      d.push_back(i);
      if (i * i != n) {
        d.push_back(n / i);
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < d.size(); ++i) {
    if (d[i] != 1 && n % (d[i] - 1) == n / (d[i] - 1)) {
      ans += d[i] - 1;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;

  vector<ll> d;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      d.push_back(i);
      if (i * i != n) {
        d.push_back(n / i);
      }
    }
  }

  sort(d.rbegin(), d.rend());

  ll ans = 0;
  for (int i = 0; i < d.size(); ++i) {
    if (n % (d[i] - 1) == n / (d[i] - 1)) {
      ans += d[i] - 1;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;

  vector<ll> d;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      d.push_back(i);
      if (i * i != n) {
        d.push_back(n / i);
      }
    }
  }

  sort(d.rbegin(), d.rend());

  ll ans = 0;
  for (int i = 0; i < d.size(); ++i) {
    if (d[i] != 1 && n % (d[i] - 1) == n / (d[i] - 1)) {
      ans += d[i] - 1;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

long long res, n, m, i;

int main() {
  cin >> n;
  for (i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      m = n / i;
      m--;
      if (n / m == n % m)
        res += m;
      ;
    }
  }
  cout << res;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

long long res, n, m, i;

int main() {
  cin >> n;
  for (i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      m = n / i;
      m--;
      if (m != 0) {
        if (n / m == n % m)
          res += m;
      }
    }
  }
  cout << res;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll n, ans;

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;

  for (ll mod = 1; mod * mod <= n; mod++) {
    if ((n % mod) || n % (n / mod - 1) != mod)
      continue;
    ans += n / mod - 1;
  }

  cout << ans;
}


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

ll n, ans;

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;

  for (ll mod = 1; mod * mod <= n; mod++) {
    if ((n % mod) || (n == 1 && mod == 1) || n % (n / mod - 1) != mod)
      continue;
    ans += n / mod - 1;
  }

  cout << ans;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;

bool check(int i) { return n / i == n % i; }

signed main() {
  cin >> n;
  int ans = 0ll;
  for (int i = 1ll; i * i <= n; i++) {
    if (n % i == 0ll) {
      if (check(n / i - 1ll))
        ans += (n / i - 1ll);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;

bool check(int i) { return n / i == n % i; }

signed main() {
  cin >> n;
  int ans = 0ll;
  for (int i = 1ll; i * i <= n; i++) {
    if (n % i == 0ll) {
      int m = n / i - 1ll;
      if (m != 0 && n / m == n % m)
        ans += m;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
  ll number = 1000000000000;
  cin >> number;

  ll result = 0;
  for (ll i = 1; i * i <= number; ++i) {
    if ((number - i) % i == 0) {
      ll j = (number - i) / i;
      if (number / j == number % j) {
        result += j;
      }
    }
  }

  cout << result << endl;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
  ll number = 1000000000000;
  cin >> number;

  ll result = 0;
  for (ll i = 1; i * i <= number; ++i) {
    if ((number - i) % i == 0) {
      ll j = (number - i) / i;
      if (j == 0) {
        continue;
      }
      if (number / j == number % j) {
        result += j;
      }
    }
  }

  cout << result << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
LL N;
LL s = 1e6 + 1;
int main() {
  cin >> N;
  LL ans = 0;
  REP(i, sqrt(N)) {
    if (N % (i + 1) == 0) {
      if ((i + 1) > N / (i + 1))
        continue;
      LL m = N / (i + 1) - 1;
      if (N / m == (N % m)) {
        ans += (N / (i + 1) - 1);
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
LL N;
LL s = 1e6 + 1;
int main() {
  cin >> N;
  LL ans = 0;
  REP(i, sqrt(N)) {
    if (N % (i + 1) == 0) {
      if ((i + 1) > N / (i + 1))
        continue;
      LL m = N / (i + 1) - 1;
      if (m <= 0)
        continue;
      if (N / m == (N % m)) {
        ans += (N / (i + 1) - 1);
      }
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sperase(v, n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n, ans;

signed main() {
  cin >> n;
  int hoge = (int)sqrt(n);
  rep1(i, hoge) {
    int tmp = (n - 1) / i;
    if (n / tmp == n % tmp)
      ans += tmp;
  }
  cout << ans << endl;
}


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

#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sperase(v, n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n, ans;

signed main() {
  cin >> n;
  int hoge = (int)sqrt(n);
  rep1(i, hoge) {
    int tmp = (n - 1) / i;
    if (!tmp)
      continue;
    if (n / tmp == n % tmp)
      ans += tmp;
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  unsigned long sum = 0;
  unsigned long n;
  cin >> n;
  for (unsigned long i = 1; i <= (unsigned long)sqrt(n); i++) {
    if (n % i != 0)
      continue;
    unsigned long j = n / i;
    // check i-1
    if ((i - 1) != 0) {
      if (n / (i - 1) == n % (i - 1))
        sum += (i - 1);
    }
    // check j-1
    if (n / (j - 1) == n % (j - 1))
      sum += (j - 1);
  }
  cout << sum << endl;
}


Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  unsigned long sum = 0;
  unsigned long n;
  cin >> n;
  for (unsigned long i = 1; i <= (unsigned long)sqrt(n); i++) {
    if (n % i != 0)
      continue;
    unsigned long j = n / i;
    // check i-1
    if ((i - 1) != 0) {
      if (n / (i - 1) == n % (i - 1))
        sum += (i - 1);
    }
    // check j-1
    if ((j - 1) != 0) {
      if (n / (j - 1) == n % (j - 1))
        sum += (j - 1);
    }
  }
  cout << sum << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define REP(i, x) for (int i = 0; i < x; i++)
#define REPP(i, x, y) for (int i = x; i <= y; i++)
#define SI(x) scanf("%d", &x)
#define SL(x) scanf("%lld", &x)
#define MX3(x, y, z) max({x, y, z})
#define MX4(x, y, z, p) max({x, y, z, p})
#define MX5(x, y, z, p, q) max({x, y, z, p, q})
#define MN3(x, y, z) min({x, y, z})
#define MN4(x, y, z, p) min({x, y, z, p})
#define MN5(x, y, z, p, q) min({x, y, z, p, q})
#define amax(x, y) x = max(x, y)
#define amin(x, y) x = min(x, y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef tuple<int, int, int> ti;
typedef tuple<ll, ll, ll> tl;
// #####################################################################

void solve() {

  ll n;
  SL(n);
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll x = n / i - 1;
      if (n / x == n % x)
        ans += x;
    }
  }
  printf("%lld\n", ans);
}

void init() {}

int main() {
  init();
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define REP(i, x) for (int i = 0; i < x; i++)
#define REPP(i, x, y) for (int i = x; i <= y; i++)
#define SI(x) scanf("%d", &x)
#define SL(x) scanf("%lld", &x)
#define MX3(x, y, z) max({x, y, z})
#define MX4(x, y, z, p) max({x, y, z, p})
#define MX5(x, y, z, p, q) max({x, y, z, p, q})
#define MN3(x, y, z) min({x, y, z})
#define MN4(x, y, z, p) min({x, y, z, p})
#define MN5(x, y, z, p, q) min({x, y, z, p, q})
#define amax(x, y) x = max(x, y)
#define amin(x, y) x = min(x, y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef tuple<int, int, int> ti;
typedef tuple<ll, ll, ll> tl;
// #####################################################################

void solve() {

  ll n;
  SL(n);
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll x = n / i - 1;
      if (x == 0)
        continue;
      if (n / x == n % x)
        ans += x;
    }
  }
  printf("%lld\n", ans);
}

void init() {}

int main() {
  init();
  solve();
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= sqrt(n); i++) {
    ll t = n / i - 1;
    if (n / t == n % t)
      ans += t;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= sqrt(n); i++) {
    ll t = n / i - 1;
    if (t == 0)
      continue;
    if (n / t == n % t)
      ans += t;
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n, ans;
vector<ll> v;
int main() {
  cin >> n;

  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      v.pb(i);
      if (i * i != n) {
        v.pb(n / i);
      }
    }
  }
  v.pb(n);

  for (int xD = 0; xD < v.size(); xD++) {
    ll x = v[xD];
    if (n == x * (n / (x - 1)))
      ans += x - 1;
  }

  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n, ans;
vector<ll> v;
int main() {
  cin >> n;

  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      v.pb(i);
      if (i * i != n) {
        v.pb(n / i);
      }
    }
  }
  if (n != 1)
    v.pb(n);

  for (int xD = 0; xD < v.size(); xD++) {
    ll x = v[xD];
    if (n == x * (n / (x - 1)))
      ans += x - 1;
  }

  cout << ans;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i != 0)
      continue;
    ll x = i - 1;
    if (x != 0 && N / x == N % x) {
      ans += x;
    }
    x = N / i - 1;
    if (N / x == N % x) {
      ans += x;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i != 0)
      continue;
    ll x = i - 1;
    if (x != 0 && N / x == N % x) {
      ans += x;
    }
    x = N / i - 1;
    if (x != 0 && N / x == N % x) {
      ans += x;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main() {
  ll N;
  cin >> N;
  if (N == 0 || N == 2) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  FOR(i, 1, N) {
    if ((N - i) % i == 0 && (N - i) / i > i) {
      ans += (N - i) / i;
    } else if ((N - i) % i == 0 && (N - i) / i <= i) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main() {
  ll N;
  cin >> N;
  if (N == 0 || N == 2) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  FOR(i, 1, N) {
    if ((N - i) % i == 0 && (N - i) / i > i) {
      ans += (N - i) / i;
    } else if ((N - i) / i <= i) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

std::string ab("AB");

int count_ab(const std::string &st) {
  int ret{0};
  std::size_t pos = st.find(ab);
  while (pos != std::string::npos) {
    ++ret;
    pos = st.find(ab, pos + ab.length());
  }
  return ret;
}

int main(int argc, char **argv) {
  int64_t n, ans{0};
  cin >> n;
  for (int64_t i = 1; i < (n + 1) / 2; ++i) {
    if (n % i == 0) {
      if ((n / i - 1) > i)
        ans += (n / i - 1);
      else
        break;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

std::string ab("AB");

int count_ab(const std::string &st) {
  int ret{0};
  std::size_t pos = st.find(ab);
  while (pos != std::string::npos) {
    ++ret;
    pos = st.find(ab, pos + ab.length());
  }
  return ret;
}

int main(int argc, char **argv) {
  int64_t n, ans{0};
  cin >> n;
  for (int64_t i = 1; i < floor(sqrt(n)) + 1; ++i) {
    if (n % i == 0) {
      if ((n / i - 1) > i)
        ans += (n / i - 1);
      else
        break;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;

int main() {
  ll n;
  cin >> n;
  V<int> ms(1e6 + 1);

  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll m = n / i - 1;
      if (n / m == n % m)
        ans += m;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;

int main() {
  ll n;
  cin >> n;
  V<int> ms(1e6 + 1);

  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll m = n / i - 1;
      if (m == 0)
        continue;
      if (n / m == n % m)
        ans += m;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

// #define int long long

using ll = long long;
using pii = pair<int, int>;

const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9 + 7;

#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define rfor_(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

ll N;

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N;

  ll sum = 0;

  for (ll k = 1; k <= N / 3; ++k) {
    if (N % k == 0) {
      ll m = (N - k) / k;
      if (m <= k)
        break;
      sum += m;
      // cout << m << endl;
    }
  }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

// #define int long long

using ll = long long;
using pii = pair<int, int>;

const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9 + 7;

#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define rfor_(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

ll N;

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N;

  ll sum = 0;

  for (ll k = 1; (k * k + k) < N; ++k) {
    if (N % k == 0)
      sum += (N - k) / k;
  }

  cout << sum << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long ans = 0, N;
  cin >> N;
  for (int i = 1; i <= sqrt(N) + 1; i++) {
    if (N % (N / i - 1) == N / (N / i - 1))
      ans += N / i - 1;
  }
  cout << ans;
}

Fixed submission:
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long ans = 0, N;
  cin >> N;
  if (N == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= sqrt(N); i++) {
    if (N % (N / i - 1) == N / (N / i - 1))
      ans += N / i - 1;
  }
  cout << ans;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  ll sq = sqrt(N);
  for (ll i = 1; i <= sq; i++) {
    if (N % i == 0) {
      ll m = N / i - 1;
      if (N / m == N % m)
        ans += m;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = 0;
  ll sq = sqrt(N);
  for (ll i = 1; i <= sq; i++) {
    if (N % i == 0) {
      ll m = N / i - 1;
      if (N / m == N % m)
        ans += m;
    }
  }
  cout << ans << endl;
  return 0;
}