alexjercan/bugnet huggingface dataset:
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD = 1000000007;
vll dx{0, 1, 0, -1};
vll dy{1, 0, -1, 0};

int main() {
  int N;
  cin >> N;
  int res = 0;
  for (int c = 1; c < N; c++) {
    int ab = N - c;
    for (int a = 1; a * a <= ab; a++) {
      if (ab % a == 0) {
        res++;
        if (ab / a != a) {
          res++;
        }
      }
    }
  }
  cout << res;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD = 1000000007;
vll dx{0, 1, 0, -1};
vll dy{1, 0, -1, 0};

int main() {
  ll N;
  cin >> N;
  ll res = 0;
  for (ll c = 1; c < N; c++) {
    ll ab = N - c;
    for (ll a = 1; a * a <= ab; a++) {
      if (ab % a == 0) {
        res++;
        if (ab / a != a) {
          res++;
        }
      }
    }
  }
  cout << res;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  int n;
  cin >> n;
  int count = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      int ans = i * j;
      if (ans < n) {
        count++;
      } else {
        break;
      }
    }
  }
  cout << count;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  int n;
  cin >> n;
  int count = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      int ans = i * j;
      if (ans < n) {
        count++;
      }
    }
  }
  cout << count - 1;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  long long count = 0;
  for (int i = 1; i <= N - 1; i++) {
    count += ((N - 1) / i);
  }

  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  long long count = 0;
  for (int c = 1; c < N; c++) {
    int p = N - c;
    for (long long i = 1; i * i <= p; i++) {
      if (p % i == 0) {
        count++;
        if (i * i != p)
          count++;
      }
    }
  }
  cout << count << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, ans = 0;
  cin >> N;
  for (int a = 1; a < N; a++) {
    ans += (N - 1) / a;
  }
  cout << ans;
}


Error: TLE

Fixed submission:

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

long long NNN(long long a) {
  long long cnt = 0;
  for (ll i = 1; i * i <= a; i++) {
    if (i * (a / i) == a)
      cnt += 2;
    if (i * i == a)
      cnt--;
  }
  return cnt;
}

int main() {
  ll N, ans = 0;
  cin >> N;
  for (ll i = 1; i < N; i++)
    ans += NNN(N - i);
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define very_slow                                                              \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int
int32_t main() {
  very_slow
  //	no_of_test(x)
  {
    int n;
    cin >> n;
    int cnt = 0;
    /* map<int,int>mp;
     for(int i=1;i<=n-1;i++)
     {
             for(int j=1;j<=n-1;j++)
             {
                     if(i*j<=n-1)
                     {
                             mp[i*j]++;
                     }
             }
     }
     int cnt=0;
     for(auto x:mp)
     {
    cnt+=x.second;
     }*/
    int w = 1;
    while (w < n) {
      int r;
      if (n % w == 0) {
        r = (n / w) - 1;
      } else {
        r = (n / w);
      }

      cnt += (r);
      w++;
    }
    int k = sqrt(n);
    cout << cnt << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define very_slow                                                              \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int
int32_t main() {
  very_slow
  //	no_of_test(x)
  {
    int n;
    cin >> n;
    //  int cnt=0;
    map<int, int> mp;
    for (int i = 1; i <= n - 1; i++) {
      for (int j = 1; j <= n - 1; j++) {
        if (i * j <= n - 1) {
          mp[i * j]++;
        }
      }
    }
    int cnt = 0;
    for (auto x : mp) {
      cnt += x.second;
    }
    cout << cnt << '\\n';
  }
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n = 0, i = 1, j = 1, k = 1, cnt = 0;

  cin >> n;

  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      k++;
      cnt += 1;
      if (i * j + k > n) {
        break;
      }
    }
    k = 1;
  }
  cout << cnt;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n = 0, i = 1, j = 1, k = 1, cnt = 0;

  cin >> n;

  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      for (k = 1; k < n; k++) {
        if ((i * j + k) == n) {
          cnt += 1;
        }
      }
    }
  }
  cout << cnt;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int sum = 0;
  for (int i = 1; i < n; ++i) {
    sum += (n - 1) / i;
  }
  cout << sum << "\\n";
}

Error: TLE

Fixed submission:

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

#define ll long long

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

  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < n; ++j) {
      for (int k = 1; k <= n - i * j; ++k) {
        if (n - k == i * j)
          ++ans;
      }
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //PBDS
#include <ext/pb_ds/tree_policy.hpp>     //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pi pair<int, int>
#define deb(x) cerr << #x << " : " << x << endl;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int, int>
#define PI 3.141592653589
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define f(i, x, n) for (int i = x; i < n; i++)
#define rf(i, x, n) for (int i = n - 1; i >= x; i--)
#define check(x) cerr << #x << " : " << x << endl;
#define ordered_set                                                            \\
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \\
       tree_order_statistics_node_update>
#define fbo find_by_order // return iterator PBDS
#define ook order_of_key  // return number :)) PBDS
#define baar exit(0)
#define INF 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
signed main() {
  fast int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int val = n / i;
    ans += val;
    if (n % i == 0)
      ans--;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //PBDS
#include <ext/pb_ds/tree_policy.hpp>     //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pi pair<int, int>
#define deb(x) cerr << #x << " : " << x << endl;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int, int>
#define PI 3.141592653589
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define f(i, x, n) for (int i = x; i < n; i++)
#define rf(i, x, n) for (int i = n - 1; i >= x; i--)
#define check(x) cerr << #x << " : " << x << endl;
#define ordered_set                                                            \\
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \\
       tree_order_statistics_node_update>
#define fbo find_by_order // return iterator PBDS
#define ook order_of_key  // return number :)) PBDS
#define baar exit(0)
#define INF 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
signed main() {
  fast int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (i / j == j)
          ans++;
        else
          ans += 2;
      }
    }
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX_N = 1000005;
std::vector<ll> num_divisor(MAX_N, 0);

void init_num_divisor() {
  for (int i = 1; i < MAX_N; ++i) {
    for (int j = i; j < MAX_N; j += i) {
      num_divisor[j]++;
    }
  }
}

int main() {
  init_num_divisor();
  int N;
  cin >> N;
  ll cnt = 0;
  for (int c = 1; c < N; ++c)
    cnt += num_divisor[c];
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

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

const int MAX_N = 1000005;
std::vector<ll> num_divisor(MAX_N, 0);

ll init_num_divisor() {
  for (int i = 1; i < MAX_N; ++i) {
    for (int j = i; j < MAX_N; j += i) {
      num_divisor[j]++;
    }
  }
}

int main() {
  init_num_divisor();
  int N;
  cin >> N;
  ll cnt = 0;
  for (int c = 1; c < N; ++c)
    cnt += num_divisor[c];
  cout << cnt << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    ans += (n - 1) / i;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i <= n - 1; i++) {
    for (long long j = 1; j <= (n - 1); j++) {
      if (i * j <= n - 1)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve() {
  ll n;
  cin >> n;

  ll ab = 0, ans = 0;
  for (ll a = 1; a * a < n; a++) {
    ab = a;
    ans += (n - 1) / a;
  }
  cout << 2 * ans - ab * ab << endl;
}

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


Error: TLE

Fixed submission:

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

vector<long long> enum_divisors(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  // 小さい順に並び替える
  // sort(res.begin(), res.end());
  return res;
}

void solve() {
  ll N;
  cin >> N;

  // int ans = 0;
  // for (int c = 1; c < N; c++) {
  //     for (int a = 1; a * a <= N-c; a++) {
  //         int right = N - c;
  //         if (right % a == 0) {
  //             ans++;
  //             if (right / a != a) {
  //                 ans++;
  //             }
  //         }
  //     }
  // }
  // cout << ans << endl;

  ll ans = 0;
  for (int c = 1; c < N; c++) {
    vector<ll> res = enum_divisors(N - c);
    ans += res.size();
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int c = 1; c < n; c++) {
    ll d = n - c;
    for (int a = 1; a * a <= d; a++) {
      if (d % a == 0 && d / a != a)
        ans += 2;
      else if (d % a == 0 && a * a == d)
        ans++;
    }
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, result = 0;
  cin >> N;

  for (int c = 1; c < N; c++) {
    int tmp = N - c;
    int index = sqrt(tmp);
    for (int a = 1; a <= index; a++) {
      if (tmp % a == 0) {
        result += 2;
      }
    }
    if (index * index == tmp) {
      result -= 1;
    }
  }
  cout << result << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, result = 0;
  cin >> N;

  for (int c = 1; c < N; c++) {
    int tmp = N - c;
    int index = sqrt(tmp);
    for (int a = 1; a <= index; a++) {
      if (tmp % a == 0) {
        result += 2;
        if (a == tmp / a) {
          result -= 1;
        }
      }
    }
  }
  cout << result << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> enumerate_num(ll x) {
  vector<ll> res;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res.push_back(i);
      if (i * i != x)
        res.push_back(x / i);
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int x = n - 1; x >= 1; x--) {
    for (ll i = 1; i * i <= x; i++) {
      if (x % i == 0) {
        ans += 2;
        if (i * i == x)
          ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    ans += (n - 1) / i;
  cout << ans;
}

Error: TLE

Fixed submission:

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

void divisor(ll n) {
  for (ll i = 1; i * i <= n; i++)
    if (!(n % i)) {
      if (i != n / i)
        ans += 2;
      else
        ans++;
    }
}

int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++)
    divisor(n - i);
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

using namespace std;
int main() {
  vi ans(1000001, 0);
  for (int i = 1; i < 1000000; i++) {
    for (int j = 1; j < 1000000; j++) {
      if (i * j > 1000000)
        break;
      ans.at(i * j)++;
    }
  }
  ll a, tmp = 0;
  cin >> a;
  rep(i, a) { tmp += ans.at(i); }
  cout << tmp;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
using namespace std;
template <typename T> map<T, T> prime_factor(T n) {
  map<T, T> ret;
  for (T i = 2; i * i <= n; i++) {
    T tmp = 0;
    while (n % i == 0) {
      tmp++;
      n /= i;
    }
    ret[i] = tmp;
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

template <typename T> T divisor_num(T N) {
  map<T, T> pf = prime_factor(N);
  T ret = 1;
  for (auto p : pf) {
    ret *= (p.second + 1);
  }
  return ret;
}

long long N, ans = 0;

int main() {
  cin >> N;
  rep(i, N) { ans += divisor_num(i); }
  ans -= 2;
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;

  long long ans = 0;

  for (long long a = 1; a < N; a++) {
    for (long long b = a; a * b < N; b++) {
      if (a == b) {
        ans++;
      } else {
        ans += 2;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, ans = 0;
  cin >> N;

  int A = 1, B = 1, C = 1;

  int sum = 0;
  // Aの操作
  while (sum <= N / 2) {
    if (A * B > N) {
      break;
    }
    // Bの操作
    while (sum <= N / 2) {
      if (A * B > N) {
        break;
      }
      // Cの操作
      while (sum <= N) {
        // 計算
        sum = A * B + C;
        // Nと一致したら
        if (sum == N) {
          ans++;
        }
        sum = 0;
        C++;
      }
      C = 1;
      B++;
    }
    B = 1;
    C = 1;
    A++;
  }

  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

/* It's a shot in the dark
                                But I will make it */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1000000000;

bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    int op = (n - 1) / i;
    cnt += op;
  }
  cout << cnt << "\\n";
}


Error: TLE

Fixed submission:

/* It's a shot in the dark
                                But I will make it */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1000000000;

bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    int x = n - i;
    for (int j = 1; j <= sqrt(x); j++) {
      if (x % j == 0) {
        if (j != x / j) {
          cnt += 2;
        } else {
          cnt++;
        }
      }
    }
  }
  cout << cnt << "\\n";
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    ans = ans + ((n - 1) / i);
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long cnt = 0, nt;
  for (long long c = 1; c <= n; c++) {
    nt = n - c;
    for (long long i = 1; i * i <= nt; i++) {
      if (nt % i == 0) {
        if (nt / i == i)
          cnt = cnt + 1;
        else
          cnt = cnt + 2;
      }
    }
  }
  cout << cnt;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using ll = long long;
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int ans = 0;
  int i, j, k;
  cin >> n;

  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      for (k = 1; k < n; k++) {
        if ((i * j + k) == n)
          ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}