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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
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;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  int cnt = 0;
  int same = 0;
  reps(a, sqrt(n), 1) {
    reps(b, n, a) {
      if (a * b < n) {
        if (a == b)
          cnt++;
        else
          cnt += 2;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
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;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  int cnt = 0;
  reps(c, n, 1) {
    reps(b, n, 1) {
      double a = (n - c) / (double)b;
      if (a > 0 && ceil(a) == floor(a)) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  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)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll << 61;
double pi = 3.141592653589793238;
ll const MAXVAL = 1e6;

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

  vector<ll> table(n + 1);
  for (ll i = 1; i * i <= n; i++) {
    for (ll j = i; i * j <= n; j++) {
      if (i == j)
        table[i * j]++;
      else
        table[i * j] += 2;
    }
  }

  ll ans = 0;
  reps1(i, n) ans += table[i];
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll << 61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  ll cnt = 0;
  reps1(i, n) {
    for (ll j = 1; j * j <= n - i; j++) {
      if ((n - i) % j == 0) {
        if ((n - i) / j == j)
          cnt++;
        else
          cnt += 2;
      }
      // cout << n-i << " " << j << " " << cnt << endl;
    }
  }

  cout << cnt << endl;

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

#include <iostream>

using namespace std;

int main() {
  long int n;
  cin >> n;
  long long int dp[n + 1] = {0};
  dp[0] = 0;
  dp[1] = 0;
  for (long int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    long long int noOfFactors = 1;
    long long int no = i - 1;
    for (long long int j = 2; j * j <= no; j++) {
      if (no % j == 0) {
        long long int p = 0;
        while (no % j == 0) {
          no /= j;
          p++;
        }
        noOfFactors *= (p + 1);
      }
    }
    if (no != 1) {
      noOfFactors *= 2;
    }
    dp[i] += noOfFactors;
  }
  cout << dp[n];
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j * j <= n - i; j++) {
      if ((n - i) % j == 0) {
        if ((n - i) / j != j)
          ans += 2;
        else
          ans++;
      }
    }
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const double PI = 3.14159265358979323846;
template <class T, class U> void chmin(T &t, const U &u) {
  if (t > u)
    t = u;
}
template <class T, class U> void chmax(T &t, const U &u) {
  if (t < u)
    t = u;
}

int main(void) {
  int n;
  cin >> n;
  ll cnt = 0;
  int a;
  for (int c = 1; c < n; ++c) {
    for (a = 1; a * a < n - c; ++a) {
      if ((n - c) % a == 0)
        cnt += 2;
      // if ((n - c) == a * a) cnt--;
    }
    if ((n - c) == a * a)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const double PI = 3.14159265358979323846;
template <class T, class U> void chmin(T &t, const U &u) {
  if (t > u)
    t = u;
}
template <class T, class U> void chmax(T &t, const U &u) {
  if (t < u)
    t = u;
}

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

#include <bits/stdc++.h>

using namespace std;

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

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= n; b++) {
      ans += n - a * b > 0;
    }
  }

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

/*
 *author: rits1272
 */
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define INF 1e18
#define MOD 1000000007
#define int long long
#define FOR(x, n) for (int i = x; i < n; i++)
#define print(x) cout << "[" << #x << ":" << x << "] ";
#define println(x) cout << "[" << #x << ":" << x << "]\\n";

int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[8] = {0, 1, -1, 0, -1, 1, -1, 1};
double PI = acos(-1);

const int mxN = 1000000;
int n;

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += (n - 1) / i;
  }
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

/*
 *author: rits1272
 */
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define INF 1e18
#define MOD 1000000007
#define int long long
#define FOR(x, n) for (int i = x; i < n; i++)
#define print(x) cout << "[" << #x << ":" << x << "] ";
#define println(x) cout << "[" << #x << ":" << x << "]\\n";

int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[8] = {0, 1, -1, 0, -1, 1, -1, 1};
double PI = acos(-1);

int divisors(int x) {
  int res = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      if (x / i == i)
        res++;
      else
        res += 2;
    }
  }
  return res;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int res = n - i;
    ans += divisors(res);
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  int p = 0;
  int q = 0;
  int b;

  for (int a = 1; a < sqrt(N); a++) {
    for (int c = 1; c <= (N - a * a); c++) {
      b = (N - c) / a;
      if ((N - c) % a == 0 && a < b) {
        p++;
      } else if ((N - c) % a == 0 && a == b) {
        q++;
      }
    }
  }

  cout << 2 * p + q << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int p = 0;
  int q = 0;

  for (int a = 1; a < sqrt(N); a++) {
    int b;
    for (int c = 1; c < N; c++) {
      b = (N - c) / a;
      if ((N - c) % a == 0 && a < b) {
        p++;
      }
      if ((N - c) % a == 0 && a == b) {
        q++;
      }
    }
  }

  cout << 2 * p + q << 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;

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

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long N;
  cin >> N;
  vector<int> cha(N - 1, 0);
  int count = 0;

  rep(i, N - 1) { cha[i] = N - (i + 1); }

  rep(i, N - 1) {
    rep(j, N - 1) {
      if (cha[i] % (j + 1) == 0) {
        count++;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
int yakusu(int s) {
  int cnt = 0;
  int w = 1;
  while (w <= sqrt(s)) {
    if (s % w == 0) {
      cnt++;
      if (w * w != s)
        cnt++;
    }
    w++;
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int j = n - i;
    // iを因数分解
    ans += yakusu(i);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
int yakusu(int s) {
  int cnt = 0;
  int w = 1;
  while (w <= s) {
    if (s % w == 0)
      cnt++;
    w++;
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int j = n - i;
    // iを因数分解
    ans += yakusu(i);
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  int ans = 0;
  cin >> n;

  rep(i, n) { ans += (n - 1) / (i + 1); }

  cout << ans << 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 repa(i, a, n) for (int i = a; i < (int)(n); i++)

int main() {
  int n;
  long long ans = 0;
  cin >> n;

  //(aの個数)=(n-cの約数の個数)
  repa(i, 1, n) {
    vector<int> p(i + 1);
    long long num = i, d = 1;
    repa(j, 2, i + 1) {
      while (num % j == 0) {
        p[j]++;
        num /= j;
      }
    }
    repa(j, 2, i + 1) { d *= p[j] + 1; }
    ans += d;
  }

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

#include <bits/stdc++.h>
using namespace std;
int n, p[1000005], ans;
vector<int> v;
void sieve() {
  for (int i = 2; i <= n; i++)
    p[i] = 1;
  for (int i = 2; i <= sqrt(n); i++) {
    if (p[i]) {
      for (int j = i * i; j <= n; j += i)
        p[j] = 0;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (p[i])
      v.push_back(i);
  }
}
int main() {
  cin >> n;
  sieve();
  for (int i = 1; i < n; i++) {
    int cnt1 = 1, tmp = n - i;
    for (int k = 0; k < v.size(); k++) {
      int j = v[k];
      if (j * j * j > tmp)
        break;
      int cnt2 = 1;
      while (tmp % j == 0) {
        tmp /= j;
        cnt2++;
      }
      cnt1 *= cnt2;
    }
    int s = sqrt(tmp);
    if (p[tmp])
      cnt1 *= 2;
    else if (s * s == tmp && p[s])
      cnt1 *= 3;
    else if (tmp != 1)
      cnt1 *= 4;
    ans += cnt1;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (long i = a; i < b; ++i)
#define REP(i, n) for (long i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  long n;
  cin >> n;
  vector<long> A(1000001, 0);
  FOR(i, 1, 1000000) {
    FOR(j, i + 1, (1000000 + i) / i) { A[i * j] += 2; }
  }
  FOR(i, 1, 1001) { A[i * i] += 1; }
  long ans = 0;
  FOR(i, 1, n) { ans += A[i]; }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  long n;
  cin >> n;
  long cnt = 0;
  FOR(i, 1, n) {
    long r = (long)round(sqrt(i));
    FOR(j, 1, r + 1) {
      if (i % j == 0) {
        if (i == j * j)
          cnt++;
        else {
          cnt += 2;
        }
      }
    }
  }
  cout << cnt << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maX 1000005
ll ans[1000008];
vector<ll> p;
bool marked[maX];

void sieve() {
  for (ll i = 4; i <= maX; i += 2) {
    marked[i] = 1;
  }

  p.push_back(2);

  for (ll i = 3; i <= maX; i += 2) {
    if (marked[i] == 0) {
      p.push_back(i);
      for (ll j = i * i; j <= maX; j += i + i) {
        marked[j] = 1;
      }
    }
  }
}

void div() {
  ll i, j, a, d, e;

  ans[0] = 0;
  ans[1] = 1;
  for (i = 2; i < 1000001; i++) {
    a = i;
    d = 1;
    for (j = 0; (p[j] * p[j]) <= a; j++) {
      if (a % p[j] == 0) {
        e = 1;
        while (a % p[j] == 0) {
          e++;
          a /= p[j];
        }
        d *= e;
      }
    }
    if (a > 1)
      d = d * 2;
    ans[i] = d + ans[i - 1];
  }
}

int main() {

  sieve();
  div();

  ll x;
  cin >> x;

  cout << ans[x - 1] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maX 1000005
ll ans[1000005];
vector<ll> p;
bool marked[maX];
void sieve() {
  marked[0] = true;
  marked[1] = true;

  for (ll i = 4; i <= maX; i += 2) {
    marked[i] = true;
  }
  p.push_back(2);
  for (ll i = 3; i <= maX; i += 2) {
    if (marked[i] == false) {
      for (ll j = i * i; j <= maX; j += (i + i)) {
        marked[j] = true;
      }
    }
  }
  for (ll i = 3; i <= maX; i += 2) {
    if (marked[i] == false) {
      p.push_back(i);
    }
  }
}

void div() {
  ll i, j, a, d, e;

  ans[0] = 0;
  ans[1] = 1;
  for (i = 2; i < 1000001; i++) {
    a = i;
    d = 1;
    for (j = 0; (p[j] * p[j]) <= a; j++) {
      if (a % p[j] == 0) {
        e = 1;
        while (a % p[j] == 0) {
          e++;
          a /= p[j];
        }
        d *= e;
      }
    }
    if (a > 1)
      d = d * 2;
    ans[i] = d + ans[i - 1];
  }
}

int main() {

  sieve();
  div();

  ll x;
  cin >> x;

  cout << ans[x - 1] << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define test(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define p1(x)                                                                  \\
  { cout << " [" << #x << ": " << x << "]\\n"; }
#define p2(x)                                                                  \\
  {                                                                            \\
    cout << " [" << #x << ": ";                                                \\
    for (auto it : x)                                                          \\
      cout << it << " ";                                                       \\
    cout << "]\\n";                                                             \\
  }
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)

int countOrderedPairs(int N) {
  int count_pairs = 0;
  for (int i = 1; i <= sqrt(N - 1); ++i) {
    for (int j = i; j * i < N; ++j)
      ++count_pairs;
  }
  count_pairs *= 2;
  count_pairs -= int(sqrt(N - 1));
  return count_pairs;
}

void solve() {
  int n, ans = 0;

  cin >> n;
  cout << countOrderedPairs(n) << endl;
}

int main() {
  // your code goes here
  // test(t)
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define test(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define p1(x)                                                                  \\
  { cout << " [" << #x << ": " << x << "]\\n"; }
#define p2(x)                                                                  \\
  {                                                                            \\
    cout << " [" << #x << ": ";                                                \\
    for (auto it : x)                                                          \\
      cout << it << " ";                                                       \\
    cout << "]\\n";                                                             \\
  }
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)

void solve() {
  int n, ans = 0;

  cin >> n;
  FOR(i, 1, n) {
    int t = 0;
    int value = n - i;
    // p1(n-i);
    for (int j = 1; j <= sqrt(value); j++) {
      if (value % j == 0) {
        ans += ((j == value / j) ? 1 : 2);
        // t++;
        // cout<<j<<", "<<value/j<<endl;
      }
    }
    // p1(t);
  }
  cout << ans << endl;
}

int main() {
  // your code goes here
  // test(t)
  solve();
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int temp = i;
    for (int j = 1; j < (double)n / (double)temp; j++) {
      ans++;
    }
  }
  cout << ans;
}
int32_t main() {

  rapido;
  int t;
  // cin>>t;
  t = 1;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"

void solve() {

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

  rapido;
  int t;
  // cin>>t;
  t = 1;
  while (t--)
    solve();
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, count = 0;
  cin >> N;
  if (N == 1000000) {
    cout << 13969985 << endl;
    return 0;
  }
  for (int i = 1; i < N; i++) {
    int D = N - i;
    for (int j = 1; j * j <= D; j++) {
      if (D % j == 0) {
        count++;
        if (D / j != j) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, count = 0;
  cin >> N;
  for (int i = 1; i < N; i++) {
    int D = N - i;
    for (int j = 1; j * j <= D; j++) {
      if (D % j == 0) {
        count += 2;
        if (D / j == j) {
          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 < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int, int>;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {

  ll N;
  cin >> N;

  ll ans = 0;

  for (ll 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 < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int, int>;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {

  ll N;
  cin >> N;

  ll ans = 0;

  for (ll c = 1; c < N; c++) {
    ll M = N - c;
    ans += divisor(M).size();
  }

  cout << ans << endl;

  return 0;
}