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

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  u64 ans = 0;
  for (u64 a = 1; a < N; a++) {
    u64 tans = (N - 1) / a;
    ans += tans;
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

u64 ps(const u64 k) {
  u64 ans = 0;
  for (u64 i = 1; i <= sqrt(k); i++) {
    if (k % i == 0) {
      ans++;
      if (i * i != k)
        ans++;
    }
  }

  return ans;
}

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

  u64 ans = 0;
  for (u64 i = 1; i < N; i++) {
    ans += ps(i);
  }

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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

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

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

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

  int64_t ans = 0;

  for (int64_t 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;

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

  int64_t ans = 0;

  for (int64_t c = 1; c < n; c++) {
    int64_t x = n - c;

    for (int64_t a = 1; a * a <= x; a++) {
      if (x % a == 0) {
        ans++;
        if (a != x / a) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
// in the name of god;;
using namespace std;
////////////////////////////////////////////////////////
typedef long long ll;   //
typedef long double ld; //
////////////////////////////////////////////////////////
#define pb push_back                           //
#define vc vector<ll>                          //
#define vpl vector<pair<ll, ll>>               //
#define d double                               //
#define So(v) sort(v.begin(), v.end())         //
#define Y cout << "YES\\n"                      //
#define N cout << "NO\\n"                       //
#define rep(x, n) for (ll i = x; i <= n; ++i)  //
#define repp(x, n) for (ll i = n; i >= x; --i) //
////////////////////////////////////////////////////////
const ll MAXN = 1e6; ///
                     ////////////////////////////////////////////////////////

int main() {
  ll n, ans = 0;
  cin >> n;
  //  1| 1 2 3 4 5 6 7 8 ... 99; 99;
  //  2| 1 2 3 4 5 6 7 8 ... 49; 49;
  //  3| 1 2 3 4 5 6 7 8 ... 33; 33;
  //  ...
  //  99 1;
  for (ll i = 1; i < n; ++i) {
    ll g = (n % i == 0 ? n / i - 1 : n / i);
    ans += (g < 0 ? 2 : g);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// in the name of god;;
using namespace std;
////////////////////////////////////////////////////////
typedef long long ll;   //
typedef long double ld; //
////////////////////////////////////////////////////////
#define pb push_back                           //
#define vc vector<ll>                          //
#define vpl vector<pair<ll, ll>>               //
#define d double                               //
#define So(v) sort(v.begin(), v.end())         //
#define Y cout << "YES\\n"                      //
#define N cout << "NO\\n"                       //
#define rep(x, n) for (ll i = x; i <= n; ++i)  //
#define repp(x, n) for (ll i = n; i >= x; --i) //
////////////////////////////////////////////////////////
const ll MAXN = 1e6; ///
                     ////////////////////////////////////////////////////////

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

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; ++i)
    for (ll j = 1; i * j < n; ++j)
      ++ans;
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = 2; i < n; i++) {

    ll curr = 1;
    ll val = i;
    for (int j = 2; j <= val; j++) {

      if (val % j == 0) {

        int cnt = 0;
        while (val % j == 0) {
          cnt++;
          val /= j;
        }
        curr *= (cnt + 1);
      }
    }
    ans += curr;
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define EFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INF 1e9
const int MOD = 1000000007;
typedef pair<ll, ll> P;

ll divs(ll n) {
  ll cnt = 0;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt++;
      if (n / i != i)
        cnt++;
    }
  }
  return cnt;
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define EFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INF 1e9
const int MOD = 1000000007;
typedef pair<ll, ll> P;

ll divs(ll n) {
  ll cnt = 0;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt++;
      if (n / i != i)
        cnt++;
    }
  }
  return cnt;
}

int main(void) {
  ll n, ans = 0;
  cin >> n;
  FOR(c, 1, n) {
    ll tmp = n - c;
    ans += divs(tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>

#define lli long long int
#define ld long double
#define endl "\\n"

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen(
      "D:\\\\My Folder\\\\Programming\\\\[code] Competetive Programming\\\\input.txt",
      "r", stdin);
  // for writing the output to output.txt
  freopen(
      "D:\\\\My Folder\\\\Programming\\\\[code] Competetive Programming\\\\output.txt",
      "w", stdout);
#endif

  lli N;
  cin >> N;

  lli count = 0;

  // for (lli c = 1; c<N; c++){
  // 	cout<<"c = "<<c<<endl;
  // 	lli k = N-c;
  // 	for (lli a = 1; a<N; a++){
  // 		if(k/a == floor(k/a) && floor(k/a) != 0){
  // 			count += 1;
  // 			cout<<a<<" "<<k/a<<" "<<c<<endl;
  // 			// break;
  // 		}
  // 	}
  // }

  for (lli a = 1; a < N; a++) {
    for (lli b = 1; b < N; b++) {
      if (a * b < N) {
        count += 1;
      } else
        break;
    }
  }
  cout << count;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

#define lli long long int
#define ld long double
#define endl "\\n"

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen(
      "D:\\\\My Folder\\\\Programming\\\\[code] Competetive Programming\\\\input.txt",
      "r", stdin);
  // for writing the output to output.txt
  freopen(
      "D:\\\\My Folder\\\\Programming\\\\[code] Competetive Programming\\\\output.txt",
      "w", stdout);
#endif

  lli N;
  cin >> N;

  lli count = 0;

  // for (lli c = 1; c<N; c++){
  // 	cout<<"c = "<<c<<endl;
  // 	lli k = N-c;
  // 	for (lli a = 1; a<N; a++){
  // 		if(k/a == floor(k/a) && floor(k/a) != 0){
  // 			count += 1;
  // 			cout<<a<<" "<<k/a<<" "<<c<<endl;
  // 			// break;
  // 		}
  // 	}
  // }

  for (lli a = 1; a < N; a++) {
    for (lli b = 1; b < N; b++) {
      if (a * b < N) {
        count += 1;
      }
    }
  }
  cout << count;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define square(x) x *x;
#define ll long long;

using namespace std;

long long int arr[1000001];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  long long int n;
  cin >> n;

  long long int ans = 0;
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 1; j * i < n; j++) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define square(x) x *x;
#define ll long long;

using namespace std;

long long int arr[1000001];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  long long int n;
  cin >> n;

  long long int ans = 0;
  for (long long int i = 1; i < n; i++) {
    ans += 2;
    if (i % 2 == 0) {
      for (long long int j = 2; j <= i / 2; j += 1) {
        if (i % j == 0)
          ans += 1;
      }
    } else {
      for (long long int j = 3; j <= i / 2; j += 2) {
        if (i % j == 0)
          ans += 1;
      }
    }
  }
  cout << ans - 1 << endl;

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef long long int ll;

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

  ll ans = 0;
  for (ll i = 1; i <= n - 1; i++) {
    ans += (n - 1) / i;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef long long int ll;

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

  ll ans = 0;
  for (ll i = 1; i <= n - 1; i++) {
    int sq = sqrt(i);
    for (ll j = 1; j <= sq; j++) {
      if (i % j == 0) {
        if (j * j == i) {
          ans++;
        } else {
          ans += 2;
        }
      }
    }
  }

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

#include <cmath>
#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
  ll n;
  cin >> n;
  ll p = ceil(sqrt(n - 1));
  ll cnt = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (n - (i * j) > 0) {

        cnt++;
        // cout<<i<<" "<<j<<" "<<(n-(i*j))<<"\\n";
      }
      if (i * j >= n)
        break;
    }
  }
  cout << cnt << "\\n";
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
  ll n;
  cin >> n;
  ll p = sqrt(n);
  ll cnt = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (n - (i * j) > 0)
        cnt++;
    }
  }
  cout << cnt << "\\n";
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FOR(i, a, b)                                                           \\
  for (unsigned long long i = a; i <= (unsigned long long)(b); i++)

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

  FOR(i, 1, N - 1) {
    m = (N - 1) / i + 1;
    while (i * m > N - 1) {
      m--;
    }
    ans += m;
  }
  cout << (ans - m + 1);
}

Error: TLE

Fixed submission:

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

#define FOR(i, a, b)                                                           \\
  for (unsigned long long i = a; i <= (unsigned long long)(b); i++)

int main() {
  unsigned long long N;
  cin >> N;
  unsigned long long ans = 0;
  FOR(i, 1, N - 1) {
    FOR(j, 1, i) {
      if (i % j == 0) {
        ans++;
      }
    }
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int count = 0;
  // This is brute force.
  // for(int i=1;i<n;i++){
  //     for(int j=1;j<n;j++){
  //         for(int k=1;k<n;k++){
  //             if(i*j+k==n)
  //             count++;
  //         }
  //     }
  // }

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      for (int k = 1; k < n; k++) {
        if (i * j + k == n)
          count++;
      }
    }
  }

  cout << count << "\\n";
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
#define frr(i, s, n) for (int i = s; i <= n; i++)
#define fr(i, s, n) for (int i = s; i < n; i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector<int>
#define vii vector<long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int, int>
#define mk make_pair
#define mpp map<int, int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;
void loop() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 1; j <= n - 1; j++) {
      if ((n - (i * j)) >= 1) {
        if ((n - (i * j)) <= n)
          cnt++;
        else
          break;
      } else
        break;
    }
  }
  cout << cnt << "\\n";
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  int t = 1;
  // cin>>t;
  while (t--)
    loop();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
#define frr(i, s, n) for (int i = s; i <= n; i++)
#define fr(i, s, n) for (int i = s; i < n; i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector<int>
#define vii vector<long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int, int>
#define mk make_pair
#define mpp map<int, int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;
void loop() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 1; j <= n - 1; j++) {
      for (int k = 1; k <= n - 1; k++) {
        if (((i * j) + k) == n)
          cnt++;
        if (((i * j) + k) >= n)
          break;
      }
    }
  }
  cout << cnt << "\\n";
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  int t = 1;
  // cin>>t;
  while (t--)
    loop();
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = std::int_fast32_t;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
map<ll, ll> prime;

void prime_factorize(ll n) {
  if (n <= 1)
    return;
  ll l = sqrt(n);
  FOR(i, 2, l) {
    if (n % i == 0) {
      prime_factorize(i);
      prime_factorize(ll(n / i));
      return;
    }
  }
  prime[n]++;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N;
  cin >> N;
  ll count{0};

  for (ll C = N - 1; C >= 1; --C) {
    ll i;
    prime_factorize(N - C);
    ll tmp = 1;
    for (const auto f : prime) {
      tmp *= f.second + 1;
    }
    prime.clear();
    count += tmp;
  }
  cout << count << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = std::int_fast32_t;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N;
  cin >> N;
  ll count{0};

  for (ll C = N - 1; C >= 1; --C) {
    for (ll A = 1; A <= sqrt(N - C); ++A) {
      if ((N - C) % A == 0) {
        ll B = (N - C) / A;
        count = A == B ? count + 1 : count + 2;
        // cout << A << ", " << B << ", " << C << endl;
        // ++count;
      }
    }
  }
  cout << count << endl;

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

#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 1; i < (n); i++)
using ll = long long;
using namespace std;

vector<ll> prime;

int main(int argc, const char *argv[]) {
  int n;
  int temp = 0;
  int ans = 0;
  cin >> n;

  rep(i, n) {
    temp = (n - 1) / i;
    ans += temp;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 1; i < (n); i++)
using ll = long long;
using namespace std;

vector<ll> prime;

ll p(ll n) {
  int a = 2;
  ll count = 1;
  while (n >= a) {
    if (n % a == 0) {
      count++;
    }
    a++;
  }

  return count;
}

int main(int argc, const char *argv[]) {
  ll n;
  ll temp = 0;
  ll ans = 0;
  cin >> n;

  rep(i, n) {
    temp = p(n - i);
    ans += temp;
  }
  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i)
    os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

[[maybe_unused]] constexpr ll MOD = 1000000007;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ll n;
  cin >> n;
  vector<ll> d(n + 1);
  rep(i, 1, n) {
    for (ll j = i; j < n; j += i)
      d[j]++;
  }

  ll ans = 0;
  rep(c, 1, n) ans += d[c];
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i)
    os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

[[maybe_unused]] constexpr ll MOD = 1000000007;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(c, 1, n) {
    ll ab = n - c;
    ll i = 1;
    while (i * i <= ab) {
      if (ab % i == 0) {
        if (ab / i == i)
          ++ans;
        else
          ans += 2;
      }
      ++i;
    }
  }
  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 int count = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / i; j++) {
      if (n - (i * j) > 0) {
        count++;
      }
    }
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

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

#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

vector<int> sieve(int n) {
  vector<int> res(n);
  iota(res.begin(), res.end(), 0);
  for (int i = 2; i * i < n; ++i) {
    if (res[i] < i)
      continue;
    for (int j = i * i; j < n; j += i)
      if (res[j] == j)
        res[j] = i;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> si = sieve(n);
  long long ans = 1;
  for (int c = 1; c < n - 1; ++c) {
    int t = n - c;
    int res = 1, cnt = 0, prev = -1;
    while (t > 1) {
      if (prev == si[t] || prev == -1)
        ++cnt;
      else {
        res *= cnt + 1;
        cnt = 1;
      }
      prev = si[t];
      t /= si[t];
    }
    res *= cnt + 1;
    ans += res;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int divisor(int n) {
  int res = 0;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ++res;
      if (i * i != n)
        ++res;
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int c = 1; c < n; ++c) {
    int t = n - c;
    ans += divisor(t);
  }
  cout << ans << endl;

  return 0;
}