alexjercan/bugnet huggingface dataset:
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

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

  return 0;
}


Error: -8

Fixed submission:

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

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

#include <iostream>
using namespace ::std;
#include <math.h>
int main() {

  int n, ans, m, fans;
  m = 0;
  fans = 0;
  ans = 0;
  cin >> n;
  for (int c = 1; c <= n; c++) {

    m = sqrt(n - c);

    for (int a = 1; a <= m; a++) {

      if (((n - c) % a == 0) && (n - c) / a != a) {
        ans += 2;
      } else if ((n - c) % a == 0) {
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace ::std;
int main() {

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

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

int N;
ll ans = 0;

void solve();

int main() {
  scanf("%d", &N);

  solve();

  return 0;
}

void solve() {

  for (int i = 1; i < N; i++) {
    ans += (N - 1) / i;
  }
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

#include <cstdio>

int N, ans = 0, flag = 0;

void solve();

int main() {
  scanf("%d", &N);

  solve();

  return 0;
}

void solve() {

  for (int C = 1; C < N; C++) {
    int temp = N - C;
    for (int A = 1; A <= temp; A++) {
      for (int B = 1; B <= temp; B++) {
        if (A * B > temp)
          break;
        if (A * B == temp) {
          ans++;
        }
      }
    }
  }

  printf("%d\\n", ans);
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N;
int main() {
  cin >> N;
  int count = 0;
  for (int c = 1; c < N; c++) {
    double Nc = sqrt(N - c);
    for (int a = 1; a < Nc; a++) {
      if ((N - c) % a == 0) {
        count += 2;
      }
    }
    int a = round(Nc);
    if (abs(Nc - a) < 0.0000001) {
      count += 1;
    }
  }
  cout << count;
  return 0;
}


Error: TLE

Fixed submission:

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

int N;
int main() {
  cin >> N;
  int count = 0;
  for (int c = 1; c < N; c++) {
    for (int a = 1; a < sqrt(N - c); a++) {
      if ((N - c) % a == 0) {
        count += 2;
        //        cout << "(N-c)%a==0" << endl;
        //        cout << "a:" << a << "b:" << (N-c)/a << "c:" << c << endl;
      }
    }
    int a = round(sqrt(N - c));
    if (abs(a - sqrt(N - c)) < 0.0000001) {
      count += 1;
      //      cout << "sqrt" << endl;
      //      cout << "a:" << a << "b:" << (N-c)/a << "c:" << c << endl;
    }
  }
  cout << count;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

// Alert!!! This program may have some NARGLE.
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define endl '\\n'

using namespace std;

const int Mod = 1e9 + 7, Inf = 1e9;
int n, ans = 1;

int32_t main() {
  // ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  scanf("%d", &n);
  for (int i = 2; i < n; i++) {
    int r = sqrt(i);
    for (int j = 1; j * j <= i; j++) {
      int tm = i / j;
      if ((j * tm) == i and (tm > r or i == j))
        ans += 2;
      else if ((j * tm) == i)
        ans++;
    }
  }
  printf("%d", ans);
  return 0;
}

Error: TLE

Fixed submission:

// Alert!!! This program may have some NARGLE.
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define endl '\\n'

using namespace std;

const int Mod = 1e9 + 7, Inf = 1e9;
int ans, n;
vector<int> v;

bool isPrime(int x) {
  for (int i = 2; i * i <= x; i++)
    if (!(x % i))
      return 0;
  return 1;
}

int cal(int x) {
  if (x == 1)
    return 1;
  int cnt = 0, cp = x, res = 1;
  for (int i = 0; i <= v.size() and cp != 1; i++, cnt = 0)
    while (!(cp % v[i])) {
      cp /= v[i];
      cnt++;
      if (cp % v[i])
        res *= (cnt + 1);
    }
  return res;
}

int32_t main() {
  // ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  scanf("%d", &n);
  for (int i = 2; i <= n; i++)
    if (isPrime(i))
      v.pb(i);
  if (n == 1000000)
    return cout << 13969985, 0;
  for (int i = 1; i < n; i++)
    ans += cal(i);
  printf("%d", ans);
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 1;
int cnt[N];

void sieve() {
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; j += i)
      cnt[j]++;
  }
}

int main() {
  //  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  sieve();
  int n;
  scanf("%d", &n);
  long long ans = 0;
  for (int c = 1; c < n; ++c) {
    ans += cnt[n - c];
  }
  printf("%lld\\n", ans);
}

Error: TLE

Fixed submission:

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
  //  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  int n;
  scanf("%d", &n);
  long long ans = 0;
  for (int c = 1; c <= n; ++c) {
    int ab = n - c;
    for (int a = 1; a * a <= ab; ++a) {
      if (ab % a == 0) {
        ans++;
        if (ab / a != a)
          ++ans;
      }
    }
  }
  printf("%lld\\n", ans);
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define quick                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define s(x) sort(x.begin(), x.end())
#define sr(x) sort(x.begin(), x.end(), greater<ll>())
#define v1 vector<ll>
#define p1 pair<ll, ll>
#define m1 map<ll, ll>
#define ff first
#define ss second
#define ee '\\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define f(i, x, y) for (i = x; i < y; i++)
#define mp make_pair
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

void solve() {
  ll i, n, cnt = 1, j;
  cin >> n;
  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      if (i * j < n) {
        cnt++;
      } else if (i * j >= n) {
        break;
      }
    }
  }
  cout << cnt - 1;
}

int32_t main() {
  quick;
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define quick                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define s(x) sort(x.begin(), x.end())
#define sr(x) sort(x.begin(), x.end(), greater<ll>())
#define v1 vector<ll>
#define p1 pair<ll, ll>
#define m1 map<ll, ll>
#define ff first
#define ss second
#define ee '\\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define f(i, x, y) for (i = x; i < y; i++)
#define mp make_pair
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

void solve() {
  ll i, n, j, k, cnt = 0;
  cin >> n;
  f(i, 0, n - 2) {
    f(j, 0, n - 1) {
      f(k, 0, n) {
        ll x = ((i + 1) * (j + 1)) + (k + 1);
        if (x == n) {
          cnt++;
        }
      }
    }
  }
  cout << cnt + 1 << ee;
}

int32_t main() {
  quick;
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
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>;
const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  double s = sqrt(n);
  int k = (int)s;
  ll count = 0;
  ll ans = 0;
  for (int i = 1; i < k + 1; i++) {
    for (ll j = i; j < 10000000; j++) {
      if (i * j < n) {
        if (i == j) {
          count += 1;
        } else {
          count += 2;
        }

      } else {
        break;
      }
    }
  }
  cout << count << endl;
}

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>;
const ll mod = 1000000007;

class Prime {
  // n以下の素数を列挙する
public:
  const int n;
  vector<bool> is_prime;
  vector<int> primes;
  Prime(int size) : n(size), is_prime(n + 1, true) {
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
      if (!is_prime[i])
        continue;
      primes.push_back(i);
      int tmp = 2 * i;
      while (tmp <= n) {
        is_prime[tmp] = false;
        tmp += i;
      }
    }
  }

  bool check(int x) { return is_prime[x]; }
};

struct PrimeFactorization {
  // n*n以下の数についての素因数分解
  const int n;
  Prime p;
  PrimeFactorization(int n) : n(n), p(n) {}

  map<ll, int> calc(ll a) {
    map<ll, int> ret;
    ll tmp = a;
    for (int i : p.primes) {
      int count = 0;
      while (tmp % i == 0) {
        ++count;
        tmp /= i;
      }
      if (count > 0)
        ret[i] = count;
    }
    if (tmp > 1)
      ret[tmp] = 1;
    return ret;
  }
};

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  PrimeFactorization pf(1000000);
  map<ll, int> factors;
  rep(i, n) {
    ll anss = 1;
    factors = pf.calc(i);
    for (auto it : factors) {
      anss = anss * it.second;
    }
    ans += anss;
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n, t, x, y, m, q;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll div[1000001] = {0};
  for (int i = 1; i < 1000001; i++) {
    for (int j = i; j < 1000001; j += i) {
      div[j]++;
    }
  }
  cin >> n;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += div[n - i];
  }
  cout << ans;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n, t, x, y, m, q;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll div[1000001] = {0};
  for (int i = 1; i < 1000001; i++) {
    for (int j = i; j <= 1000001; j += i) {
      div[j]++;
    }
  }
  cin >> n;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += div[n - i];
  }
  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 ans = 0;
  for (long long A = 1; A < N; A++) {
    long long B = N / A;
    long long C = N % A;
    if (C > 0) {
      ans += B;
    } else
      ans += B - 1;
  }

  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 C = 1; C < N; C++) {
    long long AB = N - C;
    for (long long A = 1; A * A <= AB; A++) {
      if (AB % A == 0) {
        ans++;
        if (AB / A != A)
          ans++;
      }
    }
  }

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  int count = 0;
  for (long long i = 1; i < N; i++) {
    int a = sqrt(N - i);
    for (int j = 1; j <= a; j++) {
      if ((N - i) % j == 0) {
        long long b = (N - i) / j;
        if (b == j) {
          count++;
        } else {
          count++;
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Unionfind {
  vector<int> par;
  vector<int> sizes;

  Unionfind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; ++i)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    if (sizes[x] < sizes[y])
      swap(x, y);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x) { return sizes[root(x)]; }
};

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

  int n;
  cin >> n;

  int 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>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Unionfind {
  vector<int> par;
  vector<int> sizes;

  Unionfind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; ++i)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    if (sizes[x] < sizes[y])
      swap(x, y);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x) { return sizes[root(x)]; }
};

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

  ll n;
  cin >> n;

  ll cnt = 0;
  for (ll c = 1; c < n; ++c) {
    ll num = n - c;

    for (ll i = 1; i * i <= num; ++i) {
      if (num % i == 0) {
        ++cnt;
        if (i * i != num)
          ++cnt;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long int
#define ull unsigned long long int
#define forr(i, n) for (int i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\\n'
#define ce(ele) cout << ele << ' '
#define cs(ele) cout << ele << '\\n'
#define CASE(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define sor(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define vi vector<ll>
const ll md = 1e9 + 7;
const ll M1 = 998244353;
ll mod(ll n) { return ((n % md) + md) % md; }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    x = x * x;
    y = y >> 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  ll cnt = 0;
  f(i, 1, n) { cnt += (n - 1) / i; }
  cs(cnt);
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define ull unsigned long long int
#define forr(i, n) for (int i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\\n'
#define ce(ele) cout << ele << ' '
#define cs(ele) cout << ele << '\\n'
#define CASE(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define sor(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define vi vector<ll>
const ll md = 1e9 + 7;
const ll M1 = 998244353;
ll mod(ll n) { return ((n % md) + md) % md; }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    x = x * x;
    y = y >> 1;
  }
  return res;
}
ll isprime(ll n) {
  ll cnt = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}

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

  ll n;
  cin >> n;
  ll cnt = 0;
  f(i, 1, n) { cnt += isprime(n - i); }
  cs(cnt);
}
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 all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
int insum(int n) {
  int sum = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      sum += 2;
      if (i == sqrt(n))
        sum--;
    }
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  int a, b, c, result = 0, karesult = 0;
  rep(i, n - 1) {
    c = i + 1;
    karesult = insum(n - c);
    result += karesult;
  }
  cout << result << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
int insum(int n) {
  int sum = 0;
  for (int i = 1; i < n; i++) {
    if (sqrt(n) < i)
      break;
    if (n % i == 0) {
      sum += 2;
      if (i == (n + i - 1) / i)
        sum--;
    }
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  int a, b, c, result = 0, karesult = 0;
  rep(i, n - 1) {
    c = i + 1;
    karesult = insum(n - c);
    result += karesult;
  }
  result++;
  cout << result << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i, a, b) for (int i = a; i <= b; i++)
#define g(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout << "Case #" << x << ": "
#define op1(x) cout << "Scenario #" << x << ": "
#define endl "\\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const ll NEGINF = LLONG_MIN;
const int N = 18;
const ll MAXN = 1000001;

#define MAXN 1000001
ll spf[MAXN];

void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)

    spf[i] = i;

  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < MAXN; j += i)

        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

void solve(int t) {

  sieve();
  int n;
  cin >> n;

  ll cnt = 0;

  for (int i = 1; i <= n - 1; i++) {
    ll x = i;

    map<ll, ll> m;
    while (x != 1) {
      m[spf[x]]++;
      x = x / spf[x];
    }
    ll p = 1;

    for (auto i : m)
      p *= (i.S + 1);

    cnt += p;
  }

  cout << cnt << endl;
}

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

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i, a, b) for (int i = a; i <= b; i++)
#define g(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout << "Case #" << x << ": "
#define op1(x) cout << "Scenario #" << x << ": "
#define endl "\\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const ll NEGINF = LLONG_MIN;
const int N = 18;
const ll MAXN = 1000001;

void solve(int t) {

  int n;
  cin >> n;

  ll cnt = 0;

  for (int i = 1; i <= n - 1; i++) {
    ll x = i;

    for (int j = 1; j * j <= x; j++) {
      if (x % j == 0) {
        if (j == x / j)
          cnt++;
        else
          cnt += 2;
      }
    }
  }

  cout << cnt << endl;
}

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

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

#define REP(i, a, b) for (int i = (a); i < b; ++i)
#define inf 1e9 + 10
#define MOD 1000000007

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

inline ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

inline ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0)
    res += m;
  return res;
}

template <typename T> struct PrimeFact {
  vector<T> spf;
  PrimeFact(T N) { init(N); }
  void init(T N) { // 前処理。spf を求める
    spf.assign(N + 1, 0);
    for (T i = 0; i <= N; i++)
      spf[i] = i;
    for (T i = 2; i * i <= N; i++) {
      if (spf[i] == i) {
        for (T j = i * i; j <= N; j += i) {
          if (spf[j] == j) {
            spf[j] = i;
          }
        }
      }
    }
  }
  map<T, T> get(T n) { // nの素因数分解を求める
    map<T, T> m;
    while (n != 1) {
      m[spf[n]]++;
      n /= spf[n];
    }
    return m;
  }
};

int main() {
  int n;
  cin >> n;
  int sum = 0;
  REP(i, 1, n + 1) { sum += (n - 1) / i; }

  cout << sum;

  return 0;
}

Error: TLE

Fixed submission:

#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

#define REP(i, a, b) for (int i = (a); i < b; ++i)
#define inf 1e9 + 10
#define MOD 1000000007

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

inline ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

inline ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0)
    res += m;
  return res;
}

// 素因数分解
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;
}
/*  divisor_num(n)
    入力：整数 n
    出力：nの約数の個数
    計算量：O(√n)
*/
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;
}

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

  ll sum = 0;

  for (ll i = 1; i < n; ++i) {
    ll temp = n - i;
    sum += divisor_num(temp);
  }

  cout << sum;

  return 0;
}