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

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  ll res = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u = n - i;
    float t = sqrt(u);
    for (int j = 1; j <= t; j++) {
      if (u % j == 0) {
        if (j == t) {
          res++;
        } else {
          res += 2;
        }
      }
    }
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pb push_back
#define For(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MAX 100005
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif
  int n, cnt = 0, res = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u = n - i;
    int t = sqrt(n - i);
    for (int j = 1; j <= t; j++) {
      if (u % j == 0) {
        if (u / j == j) {
          res++;
        } else {
          res += 2;
        }
      }
    }
  }
  cout << res;
}
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 i = 1; i < N; i++) {
    ans += (N - 1) / i;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  long long ans = 0;
  for (long long i = 1; i < N; i++) {
    long long M = N - i;

    if (M % 2 != 0) {
      long long j = 1;
      while (true) {
        if (j * j == M) {
          ans++;
        } else if (M % j == 0) {
          ans = ans + 2;
        }
        j = j + 2;
        if (j * j > M) {
          break;
        }
      }

    } else {
      long long j = 1;
      while (true) {
        if (j * j == M) {
          ans++;
        } else if (M % j == 0) {
          ans = ans + 2;
        }
        j++;
        if (j * j > M) {
          break;
        }
      }
    }
  }

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

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

int divCount(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal,
      // count only one
      if (n / i == i)
        cnt++;

      else // Otherwise count both
        cnt = cnt + 2;
    }
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int i, j, k;
  ll ans = 0;
  for (i = 1; i < N; i++) {
    int w = N - i;
    ll e = (ll)divCount(w);
    ans += e;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

int divCount(int n) {
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (int p = 2; p * p < n; p++)
    if (hash[p] == true)
      for (int i = p * 2; i < n; i += p)
        hash[i] = false;
  int total = 1;
  for (int p = 2; p <= n; p++) {
    if (hash[p]) {
      int count = 0;
      if (n % p == 0) {
        while (n % p == 0) {
          n = n / p;
          count++;
        }
        total = total * (count + 1);
      }
    }
  }
  return total;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int i, j, k;
  ll ans = 0;
  for (i = 1; i < N; i++) {
    int w = N - i;
    ll e = (ll)divCount(w);
    ans += e;
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define e endl

void solve() {
  ll n;
  cin >> n;
  ll count = 0;
  for (ll i = 1; i < n; i++) {
    count += n / i;
    if (n % i == 0)
      count--;
  }
  cout << count << e;
}

int main() {
  // ll t; cin >> t; while (t--)
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define e endl

void solve() {
  ll n;
  cin >> n;
  ll count = 0;
  for (ll i = 1; i < n; i++) {
    ll c = 0;
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (i / j == j)
          c++;
        else
          c += 2;
      }
    }

    count += c;
  }
  cout << count << e;
}

int main() {
  // ll t; cin >> t; while (t--)
  solve();
}
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++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
typedef long long ll;
const ll mod = pow(10, 9) + 7;
int main() {
  ll n;
  cin >> n;

  ll ans = 0;

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

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
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;
int main() {
  cin >> N;
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    ans += divisor_num(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, m = 0, max = 0, a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int j = n / i;
    if (i * j < n) {
      m = m + j;
    } else
      m = m + j - 1;
  }
  cout << m << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define what_is(x) cerr << #x << " = " << x << endl;
bool pr[1000009];
void sieve() {
  pr[0] = 1;
  pr[1] = 1;
  for (int i = 2; i <= 1000000; ++i) {
    if (pr[i] == 0) {
      for (int j = i * 2; j <= 1000000; j += i) {
        pr[j] = 1;
      }
    }
  }
}
int divv[1000009];
int main() {
  fastIO for (int i = 1; i <= 1000000; ++i) {
    for (int j = i; j <= 1000000; j += i) {
      divv[j]++;
    }
  }

  int n;
  cin >> n;
  int ans = 0;
  for (int i = n - 1; i >= 1; --i) {
    ans += divv[i];
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define what_is(x) cerr << #x << " = " << x << endl;
ll p2[1009];
int main() {
  fastIO int n;
  cin >> n;
  int ans = 0;
  for (int i = n - 1; i >= 1; --i) {
    int x = i;
    for (int j = 1; j * j <= x; ++j) {
      if (x % j == 0) {
        if (x / j == j)
          ++ans;
        else
          ans += 2;
      }
    }
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long res = 0;
  for (long long a = 1; a < N; a++) {
    res += (N - 1) / a;
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

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

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

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

  int n;
  cin >> n;

  long long count = 0;

  for (int a = 1; a < n; a++) {
    for (int b = 1; b < n; b++) {
      if (a * b < n)
        count++;
      else
        break;
    }
  }

  cout << count;

  return 0;
}

Error: TLE

Fixed submission:

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

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

  int n;
  cin >> n;

  long long count = 0;

  for (int c = 1; c < n; c++) {
    int d = n - c;
    for (int a = 1; a <= sqrt(d); a++)
      if (d % a == 0) {
        count++;
        if (d / a != a)
          count++;
      }
  }
  cout << count;

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

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int a[100005];
int main() {
  int n;
  cin >> n;
  int num = 0;
  for (int i = 1; i <= n - 1; i++) {
    int tmp = n - i;
    for (int j = 1; j <= sqrt(tmp); j++) {
      if (tmp % j == 0) {
        if (j == tmp / j)
          num += 1;
        else
          num += 2;
      }
    }
  }
  cout << num << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // LL t; cin>>t;
  // while(t--){

  // }
  LL n;
  cin >> n;
  LL sum = 0;
  for (int i = 1; i < n; i++) {
    sum += (n - 1) / i;
  }
  cout << sum;
}

Error: TLE

Fixed submission:

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

LL divCount(LL n) {
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (LL p = 2; p * p < n; p++)
    if (hash[p])
      for (LL i = p * 2; i < n; i += p)
        hash[i] = false;
  LL total = 1;
  for (LL p = 2; p <= n; p++) {
    if (hash[p]) {
      LL count = 0;
      if (n % p == 0) {
        while (n % p == 0) {
          n = n / p;
          count++;
        }
        total = total * (count + 1);
      }
    }
  }
  return total;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // LL t; cin>>t;
  // while(t--){

  // }
  LL n;
  cin >> n;
  LL sum = 0;
  for (LL i = n - 1; i >= 1; i--) {
    sum += divCount(i);
  }
  cout << sum;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  int aa = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (i * j >= n) {
        break;
      }
      aa++;
    }
  }
  cout << aa << endl;
  return (0);
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define er erase
#define line cout << "\\n";
#define mod 1000000007

int main() {
  fast ll n;
  cin >> n;
  ll sum = 0;
  for (ll x = 1; x < n; x++) {
    for (ll j = 1; j < n; j++) {
      if (x * j < n)
        sum++;
      else
        break;
    }
  }
  cout << sum << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define er erase
#define line cout << "\\n";
#define mod 1000000007
long long calculatedivisors(long long n) {
  long long cnt = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {

      if (n / i == i)
        cnt++;

      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}

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

  long long sum = 0;
  for (long long x = n - 1; x >= 2; x--) {
    long long temp = calculatedivisors(x);
    sum += temp;
  }
  cout << sum + 1;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

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

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

using ll = long long;
#define mod 998244353

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n - 1; i++) {
    ans += (n - 1) / i;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using ll = long long;
#define mod 1000000007

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

/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

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

  ll count = 0;

  for (int i = 1; i < n; i++) {
    count += (n - 1) / i;
  }

  cout << count << "\\n";
}

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

  int T = 1;
  // cin >> T;

  while (T--) {
    solve();
  }

  return 0;
}


Error: TLE

Fixed submission:

/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

ll count_factors(ll n) {
  ll count = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      count++;
      if (n / i != i) {
        count++;
      }
    }
  }

  return count;
}

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

  ll count = 0;

  for (int i = 1; i < n; i++) {
    count += count_factors(n - i);
  }

  cout << count << "\\n";
}

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

  int T = 1;
  // cin >> T;

  while (T--) {
    solve();
  }

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

#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int c = 1; c <= n - 1; c++) {
      int check = n - c;
      for (int r = 1; r < sqrt(check); r++) {

        if (check % r == 0) {
          ans += 2;
        }
      }
      if (sqrt(check) - (int)sqrt(check) == 0) {
        ans++;
      }
    }

    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int ans = 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) {
            ans++;
          }
        }
      }
    }

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

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

int main() {

  int n, k;
  k = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    k = k + (n - 1) / i;
  }

  cout << k;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int n, x, k, t;

  k = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    x = n - i;
    for (int j = 1; j < x + 1; j++) {
      t = x % j;
      if (t == 0) {
        k = k + 1;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll n;
  cin >> n;
  ll res[n + 1];
  res[1] = 0;
  for (ll i = 2; i <= n; i++) {
    ll count = 0;
    for (ll j = 1; j * j <= i - 1; j++) {
      if ((i - 1) % j == 0 && j == (i - 1) / j)
        count++;
      else if ((i - 1) % j == 0 && j != (i - 1) / j)
        count += 2;
    }
    res[i] = res[i - 1] + count;
  }
  cout << res[n] << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

string s;
int t;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n;
  cin >> n;

  ll cnt = 0;

  for (ll i = 1; i <= n; i++) {
    for (ll j = i; i * j <= n; j++) {
      ll c = n - (i * j);
      if (c > 0) {
        if (i == j)
          cnt++;
        else
          cnt += 2;
      }
    }
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

string s;
int t;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n;
  cin >> n;

  ll cnt = 0;

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

#include <bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define loop(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define Sp(p) cout << setprecision(25) << fixed << p << endl;
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long double PI = acos(-1);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// }}} End Header

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define loop(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define Sp(p) cout << setprecision(25) << fixed << p << endl;
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long double PI = acos(-1);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// }}} End Header

ll f(ll x) {
  ll ret = 0, another = 0;
  for (ll i = 1; i * i <= x; i++) {
    if (i * i == x)
      another++;
    else if (x % i == 0)
      ret++;
  }
  return 2 * ret + another;
}

int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll c = 1; c <= n - c; c++) {
    if (c != n - c)
      ans += (f(n - c) + f(c));
    else
      ans += f(c);
  }

  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;
  int count = 0;
  for (int i = N - 1; i > 0; i--) {
    for (int a = 1; a <= sqrt(i); a++) {
      if (a * a == i) {
        count++;
        break;
      }
      if (i % a == 0)
        count += 2;
    }
  }
  cout << count;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long int n;
  cin >> n;
  int count = 0;
  long int arr[n];
  for (int i = 1; i < n; i++) {
    arr[i] = i;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if ((arr[i] * arr[j]) + arr[k] == n) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}