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

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 1;
const int MOD = 1e9 + 7;
vector<ll> factors[N];

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

int main() {
  fast;
  ll n, ans = 0;
  cin >> n;
  sieve();
  for (int i = 1; i < n; ++i) {
    ll x = n - i;
    ans += factors[x].size();
  }
  cout << ans;
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

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

#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x) {
  std::cout << x << " ";
}

template <typename T>

void println(T x) {
  std::cout << x << "\\n";
}

signed main(void) {
  int n;
  cin >> n;
  vector<int> a(n, 2);
  a[1] = 1;
  FOR(i, 2, n + 1) {
    for (int j = 2 * i; j <= n; j += i) {
      a[j]++;
    }
  }
  int ret = 0;
  rep1(i, n) { ret += a[n - i]; }
  print(ret);
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x) {
  std::cout << x << " ";
}

template <typename T>

void println(T x) {
  std::cout << x << "\\n";
}

int enum_divisors(int N) {
  int res = 0;
  for (int i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res++;
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        res++;
    }
  }
  return res;
}
signed main(void) {
  int n;
  cin >> n;
  int ret = 0;
  rep1(i, n) { ret += enum_divisors(n - i); }
  print(ret);
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

ll yakusuu(ll x) {
  ll sum = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      sum += 1;
      if (i * i != x) {
        sum++;
      }
    }
  }
  // 約数の個数
  return sum;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  /*for(int c = 1;c < n;c++){
      ans += yakusuu(n-c);
  }*/
  for (int a = 1; a < n; a++) {
    if (n % a == 0) {
      ans += (n / a) - 1;
    } else {
      ans += n / a;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

ll yakusuu(ll x) {
  ll sum = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      sum += 1;
      if (i * i != x) {
        sum++;
      }
    }
  }
  // 約数の個数
  return sum;
}

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

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

#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define eps 1e-7
#define inf 0x3f3f3f3f
#define endl '\\n'

int main() {
  cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
  long long n;
  cin >> n;

  long long ans = 0;

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

  cout << ans;
}


Error: TLE

Fixed submission:

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

#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define eps 1e-7
#define inf 0x3f3f3f3f
#define endl '\\n'

int main() {
  cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
  long long n;
  cin >> n;

  long long ans = 1;

  for (long long i = 2; i < n; ++i) {
    long long cnt = 0, bruh = 0;
    for (long long j = 1; j * j <= i; ++j) {
      if (i % j == 0) {
        if (i / j != j)
          cnt += 2;
        else
          cnt++, ++bruh;
      }
    }
    debug(i, cnt);
    ans += cnt;
  }

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

template <typename T> vector<T> smallest_prime_factors(T n) {
  vector<T> spf(n + 1);
  for (int 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) {
        // iを持つ整数かつまだ素数が決まっていないなら
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }

  return spf;
}

template <typename T> vector<T> factolization(T x, vector<T> &spf) {
  vector<T> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x /= spf[x];
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  constexpr int MAX = 1000000;

  auto spf = smallest_prime_factors(MAX);

  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i < n; i++) {
    int count = 1;
    map<int, int> mp;
    auto result = factolization(n - i, spf);
    for (auto z : result)
      mp[z]++;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
      count *= itr->second + 1;
    }
    ans += count;
  }
  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 rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep2(i, 1, n) ans += enum_counter(n - i);
  cout << ans << 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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  ll 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>
using namespace std;
int main()

{
  int N;
  int a, b, c;
  int kount = 0;
  cin >> N;
  for (a = 1; a <= N; a++) {
    for (b = 1; b <= N; b++) {
      for (c = 1; c <= N; c++) {
        int sum = 0;
        sum = a * b + c;
        if (sum == N) {
          kount++;
        }
      }
    }
  }
  cout << kount << "\\n";
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\\n'
#define mod 998244353
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};

// unordered_map<ll,ll> m1 ;
void solve() {

  ll n;
  cin >> n;
  vector<ll> arr(n + 1, 1);
  for (ll i = 1; i <= n; i++) {
    for (ll j = i * 2; j <= n; j += i)
      arr[j]++;
  }
  ll ans = 0;
  for (ll j = 1; j < n; j++)
    ans += arr[j];
  cout << ans << endl;
}

// cout << arr2[n-1]<< endl;

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};

vector<ll> p;
void seive(ll x) {

  for (ll i = 2; i <= sqrt(x); ++i) {
    if (p[i] == -1) {
      p[i] = i;
      for (ll j = i * i; j <= x; j += i)
        p[j] = i;
    }
  }
}
unordered_map<int, int> m;
ll f(ll x) {
  m.clear();
  if (x == 1)
    return 1;
  ll ans = 1;
  ll c = 1;
  while (x != 1) {
    if (p[x] == -1) {
      m[x]++;
      break;
    }
    m[p[x]] = (m[p[x]] + 1) % mod;
    x /= p[x];
  }

  for (auto x : m) {
    auto a = x.ss;

    ans = (ans % mod * (a + 1) % mod) % mod;
  }

  return ans;
}

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

  ll ans = 0;
  p.clear();
  p.resize(n, -1);
  seive(n);

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

    ans += f(i);
  }
  cout << ans << endl;
}

int main() { solve(); }
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int power(int x, int n) {
  if (x == 0)
    return 0;
  if (n == 0)
    return 1;
  if (n == 1)
    return x;
  int res = power(x, n / 2);
  res = (res * res) % mod;
  if (n % 2)
    return (res * x) % mod;
  return res;
}

int nCr(int n, int r) {
  if (r == 0)
    return 1;
  vector<int> f(n + 1);
  f[0] = 1;
  for (int i = 1; i <= n; i++)
    f[i] = (f[i - 1] * i) % mod;

  return ((f[n] * power(f[r], mod - 2)) % mod * power(f[n - r], mod - 2)) % mod;
}

const int MAX = 1000001;

// array to store prime factors
int factor[MAX] = {0};

// function to generate all prime factors
// of numbers from 1 to 10^6
void generatePrimeFactors() {
  factor[1] = 1;

  // Initializes all the positions with their value.
  for (int i = 2; i < MAX; i++)
    factor[i] = i;

  // Initializes all multiples of 2 with 2
  for (int i = 4; i < MAX; i += 2)
    factor[i] = 2;

  for (int i = 3; i * i < MAX; i++) {
    // check if it has no prime factor.
    if (factor[i] == i) {
      // Initializes of j starting from i*i
      for (int j = i * i; j < MAX; j += i) {
        // if it has no prime factor before, then
        // stores the smallest prime divisor
        if (factor[j] == j)
          factor[j] = i;
      }
    }
  }
}

int no_of_fac(int n) {
  if (n == 1)
    return 1;

  int ans = 1;
  int dup = factor[n];
  int c = 1;
  int j = n / factor[n];

  while (j != 1) {
    if (factor[j] == dup)
      c += 1;
    else {
      dup = factor[j];
      ans = ans * (c + 1);
      c = 1;
    }

    j = j / factor[j];
  }
  ans = ans * (c + 1);

  return ans;
}

int32_t main() {
  int n;
  cin >> n;
  int ans = 0;
  generatePrimeFactors();
  for (int c = 1; c < n; c++) {
    int ab = n - c;
    ans += no_of_fac(ab);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

int power(int x, int n) {
  if (x == 0)
    return 0;
  if (n == 0)
    return 1;
  if (n == 1)
    return x;
  int res = power(x, n / 2);
  res = (res * res) % mod;
  if (n % 2)
    return (res * x) % mod;
  return res;
}

int nCr(int n, int r) {
  if (r == 0)
    return 1;
  vector<int> f(n + 1);
  f[0] = 1;
  for (int i = 1; i <= n; i++)
    f[i] = (f[i - 1] * i) % mod;

  return ((f[n] * power(f[r], mod - 2)) % mod * power(f[n - r], mod - 2)) % mod;
}

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

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n, i, j, k, count = 0, p;
  cin >> n;
  p = sqrt(n);
  for (i = 1; i < n; i++) {
    for (j = 1; j * j <= (n - i); j++) {
      k = (n - i) % j;
      if (k == 0) {
        count++;
      }
    }
  }
  if (p * p == n) {
    cout << 2 * count - p + 1;
  } else {
    cout << 2 * count - p;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, j, k, count = 0;
  cin >> n;
  for (i = 1; i < n; i++) {
    for (j = 1; j <= (n - i); j++) {
      k = (n - i) % j;
      if (k == 0) {
        count++;
      }
    }
  }
  cout << count;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\\n'
#define dbg(x) cout << #x << ": " << x << endl
#define clr(x, v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

vector<int> prime;
int lp[MAXN];
void init() {
  lp[1] = 1;
  for (int i = 2; i < MAXN; i++) {
    if (!lp[i])
      lp[i] = i, prime.pb(i);
    for (int j = 0; j < sz(prime) && i * 1LL * prime[j] < 1LL * MAXN; j++) {
      lp[i * prime[j]] = prime[j];
      if (i % prime[j] == 0)
        break;
    }
  }
}
void cp() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int temp = n - i;
    int me = 1;
    map<int, int> freq;
    while (temp > 1)
      freq[lp[temp]]++, temp /= lp[temp];
    for (auto &x : freq)
      me *= (x.ss + 1);
    cnt += me;
  }
  cout << cnt - 1 << endl;
}

int main() {
  FASTIO;
  int t;
  t = 1;
  init();
  // cin >> t;
  while (t--) {
    cp();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\\n'
#define dbg(x) cout << #x << ": " << x << endl
#define clr(x, v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int temp = n - i;
    int me = 0;
    for (int j = 1; j <= sqrt(temp); j++)
      if (temp % j == 0)
        me += 1 + (j != (temp / j));
    cnt += me;
  }
  cout << cnt << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
  int n;
  cin >> n;
  int k = sqrt(n) / 1;
  // cout << "k:" << k << endl;
  int ans = 0;
  for (int a = 1; a <= k; a++) {
    ans += ((n / a) - a);
  }
  int count = 0;
  for (int i = 1; i * i <= n; i++) { // 約数をひく
    if (n % i == 0) {
      if (i * i != n)
        count += 2;
      else
        count++;
    }
  }
  // cout << "count:" << count << endl;
  ans *= 2;
  ans += k;
  ans -= count;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int c = 1; c < n; c++) {
    for (int a = 1; a * a < n; a++) {
      if ((n - c) % a == 0) {
        if (a == (n - c) / a) {
          /*
          cout << "だぶりa：" << a <<  endl;
          cout << "だぶりb：" << (n-c)/a << endl;
          cout << "c：" << c << endl;
          */
          ans++;
        } else if ((n - c) / a > a) {
          /*
          cout << "シングルa：" << a <<  endl;
          cout << "シングルb：" << (n-c)/a << endl;
          cout << "c：" << c << endl;
          */
          ans += 2;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int count = 0, i, j;
  for (i = 1; i < n; i++) {
    int tmp = n - i;
    double sq = sqrt(tmp);
    for (j = 1; j <= sq; j++) {
      if (tmp % j == 0) {
        if (sq == (double)j) {
          count++;
        } else {
          count += 2;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int count = 0, i, j;
  for (i = 1; i < n; i++) {
    double sq = sqrt(n - i);
    for (j = 1; j <= sq; j++) {
      if ((n - i) % j == 0) {
        if (sq == (double)j) {
          count++;
        } else {
          count += 2;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
typedef long long ll;

int main() {
  ll N;
  ll a, b;
  ll count, ans;

  cin >> N;
  count = 0;

  rep(a, N) {
    rep(b, N) {
      ans = a * b;
      if (a * b < N)
        count++;
      else
        break;
    }
  }
  cout << count;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
typedef long long ll;

int main() {
  ll N;
  ll a, b, c;
  ll count, ans;
  cin >> N;
  count = 0;
  rep(a, 1000) {
    rep(b, 1000) {
      rep(c, N) {
        ans = a * b + c;
        if (ans == N)
          count++;
      }
    }
  }
  cout << count;

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

#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define mp make_pair
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define MOD 1000000007
#define endl "\\n"
typedef long long ll;
using namespace std;

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = ans + (n - 1) / i;
  }

  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define mp make_pair
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define MOD 1000000007
#define endl "\\n"
typedef long long ll;
using namespace std;

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n;
  cin >> n;
  ll r = n;
  ll prod, limit, count;
  count = 0;

  for (auto i = 1; i <= n; i++) {

    prod = r - i;

    limit = sqrt(prod);
    // cerr<<limit<<" ";
    for (auto j = 1; j <= limit; j++) {
      // cerr<<"prod= "<<prod<<", "<<"j= "<<j<<endl;
      if (prod % j == 0) {
        count += 2;
        // cout<<"hi";
      }
      if (prod % j == 0 && prod / j == j)
        count--;
    }
  }

  cout << count << endl;

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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
ll mod = 1000000007;
using namespace std;

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

  cout << c << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
ll mod = 1000000007;
using namespace std;

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

  cout << c << endl;
}
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 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() {
  int n, i = 1, ans = 0;
  cin >> n;
  while (i != n) {
    int x = n - i;
    for (int j = 1; j <= x; j++) {
      if (x % j == 0) {
        ans++;
      }
    }
    i++;
  }
  cout << ans << endl;
}