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

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10, 9) + 7;

template <typename T> vector<T> getValues(int num) {
  vector<T> values(num);
  for (int i = 0; i < num; i++) {
    cin >> values.at(i);
  }
  return values;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int a = 1; a < N; a++) {
    for (int b = 1; b < N; b++) {
      if (a * b >= N) {
        break;
      }
      ans++;
    }
  }
  printl(ans);
}


Error: TLE

Fixed submission:

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10, 9) + 7;

template <typename T> vector<T> getValues(int num) {
  vector<T> values(num);
  for (int i = 0; i < num; i++) {
    cin >> values.at(i);
  }
  return values;
}

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

#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long n, i, p, j, s, k, total = 0;
  cin >> n;
  for (i = 1; i <= (n - 1); i++) {
    for (j = 1; j <= (n - 1); j++) {
      if ((i * j) < n) {
        total++;
      } else {
        break;
      }
    }
  }
  cout << total << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long n, i, p, j, s, k, total = 0;
  cin >> n;
  for (i = 1; i <= n - 1; i++) {
    p = n - i;
    s = 0;
    for (j = 1; j <= sqrt(p); j++) {
      if (p % j == 0) {
        s++;
      }
    }
    total += (2 * s);
    k = sqrt(p);
    if ((k * k) == p) {
      total--;
    }
  }
  cout << total << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n, cnt = 0;
  cin >> n;

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

  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int n, a, b, cnt = 0, eq_cnt = 0;
  cin >> n;

  for (a = 1; a <= n - 1; a++) {
    for (b = 1; b <= a; b++) {
      if (a * b < n) {
        cnt++;
        if (a == b) {
          eq_cnt++;
        }
      }
    }
  }
  cnt = cnt * 2 - eq_cnt;

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

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

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


Error: TLE

Fixed submission:

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

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

#include <iostream>
using namespace std;

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

  unsigned long long result = 0;
  for (uint a = 1; a < N; a++) {
    uint b = (N - 1) / a;
    result += b;
  }
  cout << result;
  return 0;
}

Error: TLE

Fixed submission:

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

unsigned long long getResult(const uint n) {
  uint a, b, c;
  unsigned long long pattern = 0;
  for (c = 1; c < n; c++) {
    uint ab = n - c;
    for (b = 1;; b++) {
      a = ab / b;
      if (a < b) {
        break;
      }
      if (ab % b == 0) {
        pattern += (a == b) ? 1 : 2;
      }
    }
  }
  return pattern;
}

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

  unsigned long long result = getResult(N);
  cout << result;
  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 = 1; i < n; i++) {
    int l = n - i;
    for (int j = 1; j * j <= l; j++) {
      if (l % j == 0) {
        if (j == (l / j))
          count++;
        else
          count += 2;
      }
    }
  }
  cout << count;
  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;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    ll ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  int n;
  cin >> n;
  ll cnt = 0;
  REP(c, n) {
    const auto &pf = prime_factorize(n - c);
    ll res = 1;
    for (auto p : pf)
      res *= p.second + 1;
    cnt += res;
  }
  cout << cnt << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  REP(c, n + 1) {
    double sqr = sqrt(c);
    if (floor(sqrt(c)) == sqrt(c))
      cnt++;
    REP(a, sqr) {
      if ((n - c) % a == 0) {
        int b = (n - c) / a;
        if (b != 0)
          cnt += 2;
      }
    }
  }
  if (floor(sqrt(n)) == sqrt(n))
    cnt--;
  cout << cnt << '\\n';
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;

typedef long long lld;
typedef vector<lld> vlld;
const lld mod = (lld)1e9 + 7;

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

  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;

typedef long long lld;
typedef vector<lld> vlld;
const lld mod = (lld)1e9 + 7;

int main() {
  lld n;
  cin >> n;
  lld ans = 0;
  for (int i = 1; i <= n; i++) {
    lld c = n - i;
    for (int j = 1; j * j <= c; j++) {
      if (c % j == 0) {
        if (c / j == j)
          ans++;
        else
          ans += 2;
      }
    }
  }

  cout << ans << "\\n";
  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<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}
ll c2(ll n) { return n * (n - 1) / 2; }
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};
int main() {
  ll n;
  cin >> n;
  ll ans = 0;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}
ll c2(ll n) { return n * (n - 1) / 2; }
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};
int main() {
  ll n;
  cin >> n;
  ll m = n;
  ll ans = 0;
  rep(i, n) {
    m--;
    for (ll j = 1; j <= sqrt(m); j++) {
      if (m % j == 0)
        ans += 2;
      if (j == sqrt(m))
        ans--;
    }
  }

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

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

int divisors(int n) {
  int div = 0;
  rep1(i, int(sqrt(n)) + 1) {
    if (n % i == 0) {
      div += 1;
      if (i != n / i) {
        div += 1;
      }
    }
  }
  return div;
}

int N;
int dp[1100000];
int ass[1100000];

int main() {

  cin >> N;

  rep1(i, 1000001) dp[i] = divisors(i);
  rep1(i, 1000001) ass[i] = ass[i - 1] + dp[i];

  cout << ass[N - 1] << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

int divisors(int n) {
  int div = 0;
  rep1(i, int(sqrt(n)) + 1) {
    if (n % i == 0) {
      div += 1;
      if (i != n / i) {
        div += 1;
      }
    }
  }
  return div;
}

int N;
int dp[1100000];
int ans;

int main() {

  cin >> N;

  rep1(i, 1000001) dp[i] = divisors(i);
  rep1(i, 1000001) ans += dp[i];

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

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

#define ll long long int
#define scan(any)                                                              \\
  for (auto &i : any)                                                          \\
    cin >> i;
#define print(any)                                                             \\
  for (auto i : any)                                                           \\
    cout << i << " ";
#define endl '\\n'
#define pb push_back
#define vll vector<ll>
#define f(i, x, y) for (i = x; i < y; i++)
#define INF LLONG_MAX
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define s(x) sort(x.begin(), x.end())
#define all(v) v.begin(), v.end()
#define p2(n, x) cout << fixed << setprecision(x) << n << endl;
#define pll pair<ll, ll>
#define ff first
#define ss second
#define blt(x) __builtin_popcount(x)

void solve() {
  ll i, j, k, n;
  cin >> n;
  ll a = 0;
  f(i, 1, n) a += ((n - 1) / i);
  cout << a;
}

int main() {

  fast ll t = 1;

  while (t--)
    solve();

  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long int
#define scan(any)                                                              \\
  for (auto &i : any)                                                          \\
    cin >> i;
#define print(any)                                                             \\
  for (auto i : any)                                                           \\
    cout << i << " ";
#define endl '\\n'
#define pb push_back
#define vll vector<ll>
#define f(i, x, y) for (i = x; i < y; i++)
#define INF LLONG_MAX
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define s(x) sort(x.begin(), x.end())
#define all(v) v.begin(), v.end()
#define p2(n, x) cout << fixed << setprecision(x) << n << endl;
#define pll pair<ll, ll>
#define ff first
#define ss second
#define blt(x) __builtin_popcount(x)
ll fun(ll n) {

  ll ans = 0;
  ll i, j, k;
  f(i, 1, (int)sqrt(n) + 1) {
    if (n % i == 0) {
      if (i == n / i)
        ans++;
      else
        ans += 2;
    }
  }
  return ans;
}
void solve() {
  ll i, j, k, n;
  cin >> n;
  ll ans = 0;
  f(i, 1, n) { ans += fun(n - i); }
  cout << ans;
}

int main() {

  fast ll t = 1;

  while (t--)
    solve();

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

#include <bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
using namespace std;

void solve() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i < n; ++i) {
    sum += (n - 1) / i;
  }

  cout << sum << endl;
}

int main() {

  /*#ifndef ONLINE_JUDGE
          freopen("input.txt","r",stdin);
          freopen("output.txt","w",stdout);
  #endif*/
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // int t;cin >> t;while(t--){solve();}
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
using namespace std;

void solve() {
  int n;
  cin >> n;
  long 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 << endl;
}

int main() {

  /*#ifndef ONLINE_JUDGE
          freopen("input.txt","r",stdin);
          freopen("output.txt","w",stdout);
  #endif*/
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // int t;cin >> t;while(t--){solve();}
  solve();
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    orderset;

vector<ll> sieve(ll n) {
  bool prim[n + 1];
  memset(prim, true, sizeof(prim));

  for (ll p = 2; p * p <= n; p++) {
    if (prim[p] == true) {
      for (ll i = p * p; i <= n; i += p)
        prim[i] = false;
    }
  }
  vector<ll> vec;
  for (int i = 2; i <= n; i++) {
    if (prim[i]) {
      vec.push_back((ll)i);
    }
  }
  return vec;
}

ll divisor(ll n) {
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int r = i;
      int l = n / i;
      if (r == l)
        ans++;
      else if (r != l)
        ans += 2;
      // st.insert(i);st.insert(n/i);
    }
  }
  return ans;
}
void solve() {
  ll n;
  cin >> n;
  ll anss = 0;
  for (ll i = 1; i <= n; i++) {
    if (i != n)
      anss += divisor(n - i);
  }
  cout << anss << "\\n";
}

int main() {
  /*#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif*/
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
vector<ll> NUM(1e6 + 20, 1);
void Div(ll n) {
  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      NUM[j]++;
    }
  }
}
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  Div(1e6);
  for (ll i = 1; i < n; i++) {
    ans += NUM[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll Div(ll n) {
  ll res = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res++;
      ll j = n / i;
      if (j != i)
        res++;
    }
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i < n; i++) {
    ll x = Div(i);
    ans += x;
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

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;
}

int N;
int ans;

signed main() {
  cin >> N;
  for (int A = 1; A <= N; ++A) {
    // cout<<A<<endl;
    ans += (N - 1) / A;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

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;
}

int N;
bool used[1000005];

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

int ans;

signed main() {
  cin >> N;
  for (int C = 1; C < N; ++C) {
    int c = divisor(N - C);
    ans += (c / 2) * 2;
    if (c % 2 != 0)
      ans++;
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> pre(N + 1, 0);

  for (int a = 1; a <= N; ++a) {
    for (int b = 1; b <= N / a; ++b) {
      ++pre[a * b];
    }
  }

  int sum = 0;

  for (int i = 1; i < N; ++i)
    sum += pre[i];

  cout << sum;
  return 0;
}

Error: 5

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> pre(N + 1, 0);

  for (int a = 1; a <= N; ++a) {
    for (int b = 1; b <= N / a; ++b) {
      ++pre[a * b];
    }
  }

  int sum = 0;

  for (int i = 1; i <= N; ++i)
    sum += pre[i];

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i, n) for (int i = 0; i < (n); ++i)

ll yakusu(ll n) {
  ll ret = 0;

  for (ll i = 1; i * i <= n;
       i++) { // ルートnまで試す。i <= sqrt(n) だと、右辺が少数になってメンドイ
    if (n % i == 0) {
      ret++;
      if (n / i != i) { // ルートnが約数の時は、2つpush_backしないように注意
        ret++;
      }
    }
  }
  return ret;
}

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

  ll res = 0;

  vector<ll> u(n + 5, 0);

  for (int i = n - 1; i >= 1; i--) {
    for (int j = i; j < n; j += i) {
      u[i]++;
    }
  }
  rep(i, n) { res += u[i]; }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i, n) for (int i = 0; i < (n); ++i)

ll yakusu(ll n) {
  ll ret = 0;

  for (ll i = 1; i * i <= n;
       i++) { // ルートnまで試す。i <= sqrt(n) だと、右辺が少数になってメンドイ
    if (n % i == 0) {
      ret++;
      if (n / i != i) { // ルートnが約数の時は、2つpush_backしないように注意
        ret++;
      }
    }
  }
  return ret;
}

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

  ll res = 0;

  for (int i = n - 1; i >= 1; i--) {
    ll tmp = yakusu(n - i);
    res += tmp;
  }
  cout << res << endl;
}