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

#include <iostream>
using namespace std;

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

  long long cnt = 0;
  for (int a = 1; a <= n; a++) {
    cnt += (n - 1) / a;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

long div(int NC) {
  long cnt = 0;
  for (long i = 1; i * i <= NC; i++) {
    if (NC % i == 0) {
      cnt++;
      if (NC / i != i)
        cnt++;
    }
  }
  return cnt;
}

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

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

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

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

  vector<ll> dp(n + 1, 1);

  for (ll i = 2; i <= n; i++) {
    ll x = i;
    while (x <= n) {
      dp[x]++;
      x += i;
    }
  }

  ll cnt = 0;

  for (ll c = 1; c <= n - 1; c++) {
    cnt += dp[n - c];
  }

  cout << cnt << endl;

  return (0);
}

Error: TLE

Fixed submission:

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

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

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

  ll cnt = 0;

  // cout << numOfFactor(n) << endl;

  for (ll c = 1; c <= n - 1; c++) {
    cnt += numOfFactor(n - c);
  }

  cout << cnt << endl;

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

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int ctr = 0;
  for (int a = 1; a < n; a++) {
    for (int b = 1; b < n; b++) {
      int c = n - (a * b);
      if (c <= 0) {
        break;
      }
      ctr++;
    }
  }
  cout << ctr;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

// It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define mem(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9 + 7;
ll res;

void solve() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    for (int j = 1; i * j < n; j++) {
      res++;
    }
  }
  cout << res << endl;
}

int main() {
  IOS;
  ll t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

Error: TLE

Fixed submission:

// It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define mem(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9 + 7;
ll res;

void solve() {
  int n;
  cin >> n;
  for (int c = n - 1; c >= 1; c--) {
    int left = n - c;
    for (int a = 1; a <= left; a++) {
      int b;
      if (left % a == 0) {
        b = left / a;
      }
      if (a && b && c && ((a * b) + c == n)) {
        res++;
      }
    }
  }
  cout << res << endl;
}

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

const int MOD = 998244353;
const int INF = 1e15;

void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

signed main() {
  fast();

  int n;
  cin >> n;

  int cnt = 0, ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (n % i == 0)
      --ans;
    ans += n / i;
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

const int MOD = 1e9 + 7;
const int INF = 1e15;

void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

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

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

const int M = (int)1e9 + 7;
typedef long long LL;

void fastIO_test(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

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

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

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

  // sieve();
  LL total = 0;
  LL x = n - 1;
  for (int c = 1; c < n; c++) {
    total += (x / c);
  }
  cout << total << "\\n";
}

int main() {
  fastIO_test();

  LL t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

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

const int M = (int)1e9 + 7;
typedef long long LL;

void fastIO_test(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int prime[1000005];
void sieve() {
  prime[0] = 1;
  prime[1] = 1;
  for (long long int i = 2; i <= 1000002; i++)
    prime[i] = i;
  for (long long int i = 2; i * i <= (1000002); i++) {
    if (prime[i] == i) {
      for (long long int j = i * i; j <= 1000002; j += i) {
        if (prime[j] == j)
          prime[j] = i;
      }
    }
  }
}

int count(int n) {
  unordered_map<int, int> m;
  while (n > 1) {
    m[prime[n]]++;
    n /= prime[n];
  }
  int ans = 1;
  for (auto k : m)
    ans *=
        (k.second +
         1); // using the divisor property (p+1)*(q+1) if num. n = (x^p)*(y^q)
  return ans;
}

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

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

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

  // sieve();
  LL total = 0;
  int numDiv;
  for (int c = 1; c < n; c++) {
    numDiv = countDivisors(n - c);
    total += numDiv;
  }
  cout << total << "\\n";
}

int main() {
  fastIO_test();

  LL 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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  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;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// 素因数分解
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;
}
long long N;
int main() {
  cin >> N;
  ll answer = 0;
  for (int i = 1; i < N; i++) {
    answer += divisor_num(i);
  }
  cout << answer << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll i, j, tot = 0;
  for (i = 1; i < n; i++) {
    for (j = 1; j * i < n; j++)
      tot++;
  }
  cout << tot;
  return 0;
}


Error: TLE

Fixed submission:

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

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

  ll n, i, m, ans = 0, j;
  cin >> n;
  ll b, s;

  for (i = n - 1; i > 0; i--) {
    m = n - i;
    for (j = 1; j <= sqrt(m); j++) {
      if (m % j == 0) {
        b = m / j;
        s = b * j;

        if (j == b)
          ans++;
        if (j != b)
          ans += 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long cnt = 0;
  for (long long A = 1; A < N; A++) {
    cnt += (N - 1) / A;
  }

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include <iostream>
// #include <utility>
// #include <string>
// #include <array>
using namespace std;

long long MOD = 1e9 + 7;
int MAX_INT = 1e9;

// 最大公約数
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

// x^y%p
long long modpow(long long x, long long y, long long p = 1) {
  long long res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = res * x % p;
    y = y >> 1;
    x = x * x % p;
  }
  return res;
}

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

  long long N;
  cin >> N;

  long long cnt = 0;
  for (long long C = 1; C <= N; C++) {
    long long ans = N;
    ans -= C;
    for (long long A = 1; A <= N - C; A++) {
      if (ans % A == 0 && (N - C) / A != 0) {
        cnt++;
      }
    }
  }

  cout << cnt << endl;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
typedef long long ll;
using namespace std;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long 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;
}

void solve(long long N) {
  ll res = 0;
  for (int i = 1; i <= N; i++) {
    res += (N - 1) / i;
  }
  cout << res << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
typedef long long ll;
using namespace std;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long 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;
}

void solve(long long N) {
  ll res = 0;
  for (int i = 1; i < N; i++) {
    vector<ll> div_num = divisor(i);
    res += div_num.size();
  }
  cout << res << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4 * atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 1e6 + 10;
int N;
ll num[MAX_N];

void cal(int x) {
  int res = 0;
  bool f = false;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      res += 2;
    }
    if (i * i == x) {
      f = true;
    }
  }
  if (f)
    res--;
  num[x] = res;
}

void solve() {
  for (int i = 1; i <= N; ++i)
    cal(i);
  ll res = 0;
  for (int c = 1; c < N; ++c) {
    res += num[N - c];
  }
  cout << res << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4 * atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 2e6 + 10;
int N;

int cal(int x) {
  int res = 0;
  bool f = false;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      res += 2;
    }
    if (i * i == x) {

      f = true;
    }
  }
  if (f)
    res--;
  return res;
}

void solve() {
  ll res = 0;
  for (int c = 1; c < N; ++c) {
    res += cal(N - c);
  }
  cout << res << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  solve();
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool prime(ll n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}
ll div(ll n) {
  ll cnt = 0;
  for (ll i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, counter = 0;
  cin >> n;
  vector<ll> a(n + 1, 1);
  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j <= n; j += i)
      a[j]++;
  }
  for (ll i = 1; i < n; i++) {
    counter += a[i];
  }
  cout << counter << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool isPerfectSquare(ll x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
bool isPrime(ll n) {
  // Corner cases
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;

  // This is checked so that we can skip
  // middle five numbers in below loop
  if (n % 2 == 0 || n % 3 == 0)
    return false;

  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}
ll div(ll n) {
  ll cnt = 0;
  for (ll i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, counter = 0;
  cin >> n;
  for (ll i = 1; i < n; i++) {
    ll a = n - i;
    if (isPrime(a)) {
      counter += 2;
    } else {
      counter += div(a);
    }
  }
  cout << counter << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

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

  for (int i = n - 1; i > 0; i--) {
    if (i % 2 != 0) {
      if (IsPrime(i) == false) {
        int j = (int)sqrt(i);
        if (pow(j, 2) == i)
          count--;
        if (j % 2 == 0)
          j -= 1;
        for (j; j > 0; j -= 2) {
          if (i % j == 0) {
            count += 2;
          }
        }
      } else {
        count += 2;
      }
    } else {
      int j = (int)sqrt(i);
      if (pow(j, 2) == i)
        count--;
      for (j; j > 0; j -= 1) {
        if (i % j == 0) {
          count += 2;
        }
      }
    }
  }

  cout << count;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

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

  for (long i = n - 1; i > 0; i--) {
    if (IsPrime(i) == false) {
      long j = 0;
      if (pow((long)sqrt(i), 2) == i)
        count--;
      for (long j = (long)sqrt(i); j > 0; j--) {
        if (i % j == 0) {
          count += 2;
        }
      }
    } else {
      count += 2;
    }
  }

  cout << count;

  return 0;
}
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 (ll i = 0; i < n; i++)
int main() {
  ll N;
  cin >> N;
  ll ans = N - 1;
  for (ll A = 2; A < N; A++) {
    ans = ans + N / A;
    if (N % A == 0)
      ans--;
  }
  cout << ans;
  cin >> N;

  return 0;
}


Error: TLE

Fixed submission:

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

  for (ll C = 1; C < N; C++) {
    n = N - C;
    for (ll A = 1; A <= n; A++) {
      if (n % A == 0) {
        ans++;
      }
    }
  }

  cout << ans;
  cin >> N;

  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

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

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

  ll n, temp = 0;
  cin >> n;

  for (ll i = 1; i <= n - 1; i++) {
    if (n % i == 0) {
      temp = temp + n / i - 1;
    } else {
      temp = temp + n / i;
    }
  }
  cout << temp << endl;
}

Error: 0

Fixed submission:

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

void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) {
  for (int i = 2; i <= n; i++)
    prime[i] = true;

  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (prime[p]) {

      a[j] = p;

      primesquare[p * p] = true;
      j++;
    }
  }
}

int countDivisors(int n) {

  if (n == 1)
    return 1;

  bool prime[n + 1], primesquare[n * n + 1];

  int a[n]; // for storing primes upto n

  // Calling SieveOfEratosthenes to store prime
  // factors of n and to store square of prime
  // factors of n
  SieveOfEratosthenes(n, prime, primesquare, a);

  // ans will contain total number of distinct
  // divisors
  int ans = 1;

  // Loop for counting factors of n
  for (int i = 0;; i++) {
    // a[i] is not less than cube root n
    if (a[i] * a[i] * a[i] > n)
      break;

    // Calculating power of a[i] in n.
    int cnt = 1;          // cnt is power of prime a[i] in n.
    while (n % a[i] == 0) // if a[i] is a factor of n
    {
      n = n / a[i];
      cnt = cnt + 1; // incrementing power
    }

    // Calculating the number of divisors
    // If n = a^p * b^q then total divisors of n
    // are (p+1)*(q+1)
    ans = ans * cnt;
  }

  // if a[i] is greater than cube root of n

  // First case
  if (prime[n])
    ans = ans * 2;

  // Second case
  else if (primesquare[n])
    ans = ans * 3;

  // Third case
  else if (n != 1)
    ans = ans * 4;

  return ans; // Total divisors
}

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

  ll n, temp = 0;
  cin >> n;

  for (ll i = 0; i < n - 1; i++) {
    temp = temp + countDivisors(n - i - 1);
  }
  cout << temp << endl;
}