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

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(), a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x, n) for (ll i = x; i < n; i++)
#define umap unordered_map<ll, ll>
#define mmap map<ll, ll>
#define mm 998244353

// typedef tree<pii,null_type,less<pii>,rb_tree_tag,
// tree_order_statistics_node_update>PBDS;

vi prime;

void sieve() {
  vi p;
  p.resize(1001, 1);
  prime.pb(2);

  for (int i = 3; i <= 1e3; i++)
    if (p[i] == 1) {
      prime.pb(i);
      for (int j = i + i; j <= 1e3; j += i)
        p[j] = 0;
    }

  return;
}

ll res(ll num) {
  if (num == 1)
    return 1;

  // ll nn = sqrt(num);

  // ll ck=0;
  // if(nn*nn==num)ck=1;

  ll result = 1;

  for (auto x : prime)
    if (x * x > num)
      break;
    else if (num % x == 0) {
      ll cnt = 0;
      while (num % x == 0) {
        num = num / x;
        cnt++;
      }
      result *= (cnt + 1);
    }

  if (num != 1)
    result *= 2;

  return result;
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  sieve();
  ll t;
  t = 1;
  // cin>>t;
  while (t--) {
    ll n;
    cin >> n;

    ll cnt = 0;

    for (int i = 1; i < n; i++) {
      ll num = n - i;
      cnt += res(num);
    }

    // cout<<res(45);
    cout << cnt;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(), a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x, n) for (ll i = x; i < n; i++)
#define umap unordered_map<ll, ll>
#define mmap map<ll, ll>
#define mm 998244353

// typedef tree<pii,null_type,less<pii>,rb_tree_tag,
// tree_order_statistics_node_update>PBDS;

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  ll t;
  t = 1;
  // cin>>t;
  while (t--) {
    ll n;
    cin >> n;

    ll cnt = 0;

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

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

    cout << cnt;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    for (int j = 1; j * j <= n - i; j++) {
      if ((n - i) % j == 0) {
        s++;
        if ((n - i) / j != j)
          s++;
      }
    }
  }
  printf("%d\\n", s);
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007

using namespace std;

long long GCD(long long x, long long y) {
  long long r, tmp;
  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  while (y != 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
long long LCM(long long x, long long y) {
  long long lcm = (x * y) / GCD(x, y);
  return lcm;
}

int bubblesort(int n) {
  vector<int> data(n);
  int num = 0;
  for (int end = n - 1; end > 0; end--) {
    for (int j = 0; j < end; j++) {
      if (data[j + 1] < data[j]) {
        int temp = data[j];
        data[j] = data[j + 1];
        data[j + 1] = temp;
        num++;
      }
    }
  }
  return num;
}

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007

using namespace std;

long long GCD(long long x, long long y) {
  long long r, tmp;
  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  while (y != 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
long long LCM(long long x, long long y) {
  long long lcm = (x * y) / GCD(x, y);
  return lcm;
}

int bubblesort(int n) {
  vector<int> data(n);
  int num = 0;
  for (int end = n - 1; end > 0; end--) {
    for (int j = 0; j < end; j++) {
      if (data[j + 1] < data[j]) {
        int temp = data[j];
        data[j] = data[j + 1];
        data[j + 1] = temp;
        num++;
      }
    }
  }
  return num;
}

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

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

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

  vector<int> c(n, 0);
  for (int i = 1; i < n; ++i) {
    for (int j = i; j < n; j += i) {
      ++c[j];
    }
  }

  int s = 0;
  for (int ci : c) {
    s += ci;
  }

  cout << s;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  int k = 1;
  for (int c = 1; c < n - 1; ++c) {
    int d = n - c;
    for (int i = 1; i <= sqrt(d); ++i) {
      if (d % i == 0) {
        k += 2;

        if (i == sqrt(d)) {
          --k;
        }
      }
    }
  }

  cout << k;

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <locale.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;

int prime[1000000] = {}; // i番目の素数
int spf[10000001];       // 1~1000000までSPFを求めておく
bool is_prime[1000001];  // is_primeがtrueならiは素数
void sieve(int n)        // n以下の素数を列挙する
{
  int p = 0;
  for (int i = 0; i <= n; i++) {
    is_prime[i] = true;
    spf[i] = i;
  }
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
        spf[j] = i;
      }
    }
  }
}

int main() {
  int x, ans = 0;
  scanf("%d", &x);
  sieve(x);
  // printf("aa");
  for (int i = 1; i < x; i++) {
    int rep = x - i, med = 1, tet = 0, mae = 1; // x-iの約数の個数がmed
    if (rep == 1) {
      ans++;
      break;
    }
    if (is_prime[rep]) {
      med = 2;
    } else {
      for (;;) {
        mae = spf[rep]; // repを割り切る最小の素数を記録しておく
        rep /= mae;
        tet++;
        if (mae != spf[rep]) {
          med = med * (tet + 1);
          tet = 0;
        }
        if (rep == 1) {
          break;
        }
      }
    }
    ans += med;
    //	printf("%d %d\\n",x-i,med);
  }
  printf("%d", ans);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <locale.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;

int prime[1000000] = {}; // i番目の素数
bool is_prime[1000001];  // is_primeがtrueならiは素数
void sieve(int n)        // n以下の素数を列挙する
{
  int p = 0;
  for (int i = 0; i <= n; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

int main() {
  int x, ans = 0;
  scanf("%d", &x);
  sieve(x);
  for (int i = 1; i < x; i++) {
    int rep = x - i, med = 1, tet = 0; // x-iの約数の個数がmed
    if (rep == 1) {
      ans++;
      break;
    }
    for (int j = 0;; j++) {
      if (rep % prime[j] == 0) {
        rep = rep / prime[j];
        tet++;
        j--;
        if (rep == 1) {
          med = med * (tet + 1);
          tet = 0;
          break;
        }
      } else if (tet != 0) {
        med = med * (tet + 1);
        tet = 0;
      }
    }
    ans += med;
    //	printf("%d %d\\n",x-i,med);
  }
  printf("%d", ans);
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int pf[1000006];
void fun() {
  pf[1] = 1, pf[0] = 1;
  for (int i = 0; i < 1000006; i++)
    pf[i] = i;
  for (int i = 2; i * i < 1000006; i++) {
    if (pf[i] == i) {
      for (int j = i; j < 1000006; j += i) {
        if (pf[j] == j)
          pf[j] = i;
      }
    }
  }
}
int fun1(int x) {
  int c = 1;
  while (x != 1) {
    int t = pf[x], c1 = 0;
    while (x % t == 0) {
      x /= pf[x];
      c1++;
    }
    c += c * c1;
  }
  return c;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(20) << fixed;

  int n;
  cin >> n;
  fun();
  int c = 0;
  for (int i = 1; i < n; i++) {
    int t = fun1(n - i);
    // cout<<t<<endl;
    c += t;
  }
  cout << c << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(20) << fixed;

  int n;
  cin >> n;
  int c = 0;
  for (int i = 1; i < n; i++) {
    int t = n - i;
    for (int j = 1; j * j <= t; j++) {
      if (t % j == 0) {
        c += 2;
        if (j == t / j)
          c--;
      }
    }
  }
  cout << c << 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 i = 1; i < n; i++) {
    for (int j = 1; j <= int(n / i); j++) {
      if (i * j != n)
        ans++;
      //			for(int k=1;k<=n-i*j;k++)
      //			{
      //				if(i*j+k==n)ans++;
      ////				cout<<i<<' '<<j<<' '<<k ;
      //			}
    }
  }
  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++) {
    for (int j = 1; j <= n; j++) {
      if (i * j < n)
        ans++;
      //			for(int k=1;k<=n-i*j;k++)
      //			{
      //				if(i*j+k==n)ans++;
      ////				cout<<i<<' '<<j<<' '<<k ;
      //			}
    }
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int32_t main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    ans += ((n + i - 1) / i) - 1;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int printDivisors(int n) {
  int king = 0;
  // Note that this loop runs till square root
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal, print only one
      if (n / i == i)
        king++;
      // printf("%d ", i);

      else // Otherwise print both
        king += 2;
      // printf("%d %d ", i, n/i);
    }
  }
  return king;
}
int32_t main() {
  int n;
  cin >> n;
  int mega = 0;
  int fact;
  for (int i = 1; i < n; ++i) {
    fact = printDivisors(n - i);
    mega += fact;
  }
  cout << mega;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long int
#define pb push_back
int main() {
  ll a, cnt = 0;
  cin >> a;
  for (ll i = 1; i <= a; i++) {
    cnt += a / i;
    if (a % i == 0)
      cnt--;
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long int
#define pb push_back
int main() {
  ll a, cnt = 0;
  cin >> a;
  for (ll i = 1; i < a; i++) {
    ll cur = a - i;
    for (ll j = 1; j <= sqrt(cur); j++) {
      if (j * j == cur)
        cnt++;
      else if (cur % j == 0)
        cnt += 2;
    }
  }
  cout << cnt << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, sum = 0;
  cin >> N;
  for (int i = 1; i < N; i++) {
    int j = 1, count = 0;
    while (i * j < N) {
      count++;
      j++;
    }
    sum += count;
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

int cal(long long M) {
  long long count_sum = 1;
  cin >> M;

  for (long long p = 2; p <= M; p++) {
    long long ex = 1;
    if (M % p != 0) {
      continue;
    }
    if (M % p == 0) {
      while (M % p == 0) {
        M = M / p;
        ex += 1;
      }
    }
    count_sum *= ex;
  }
  return count_sum;
}

int main() {
  long long N;
  cin >> N;
  long long j, M, sum = 0;
  for (long long i = 0; i < N - 1; i++) {
    j = i + 1;
    M = N - j;
    sum += cal(M);
  }
  cout << sum << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
// #include <atcoder/scc>
// #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
// using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y) {
  lli t;
  while (y != 0)
    t = x % y, x = y, y = t;
  return (x);
}

lli lcm2(lli x, lli y) {
  lli xy = x * y;
  if (xy < 0)
    xy = -xy;
  return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void) {
  int N;
  cin >> N;
  lli cnt = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N; j++) {
      int c = N - i * j;
      if (c > 0) {
        cnt++;
      } else {
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
// #include <atcoder/scc>
// #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
// using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y) {
  lli t;
  while (y != 0)
    t = x % y, x = y, y = t;
  return (x);
}

lli lcm2(lli x, lli y) {
  lli xy = x * y;
  if (xy < 0)
    xy = -xy;
  return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void) {
  int N;
  cin >> N;
  lli cnt = 0;
  bool f[N];
  fill(f, f + N, false);
  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= N - i; j++) {
      if ((N - i) % j == 0) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;

int arr[N];

int divisors[N];

int main() {

  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; j += i)
      ++divisors[j];

  long long ans = 0;
  for (int c = 1; c < n; c++) {
    int x = n - c;
    ans += divisors[x];
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;

int main() {

  int n;
  cin >> n;
  long long ans = 0;
  for (int c = 1; c < n; c++) {
    int x = n - c;
    int div = 0;
    for (int i = 1; i <= sqrt(x); i++) {
      if (x % i == 0) {
        if (x / i == i) {
          div++;
        } else
          div += 2;
      }
    }
    ans += div;
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define ps(x, noOfDecimal) fixed << setprecision(noOfDecimal) << x
using namespace std;

signed main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    vector<int> freq(n);
    for (int i = 1; i < n; i++) {
      for (int j = i; j < n; j += i) {
        freq[j]++;
      }
    }
    for (int i = 1; i < n; i++) {
      ans += freq[i];
      // cout<<freq[i]<<" ";
    }
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define ps(x, noOfDecimal) fixed << setprecision(noOfDecimal) << x
using namespace std;

int find(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      int x = i, y = n / i;
      cnt++;
      if (x != y)
        cnt++;
    }
  }
  return cnt;
}
signed main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
      int cnt = find(i);
      ans += cnt;
    }
    cout << ans;
  }
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  ll res = 0;
  // for (ll c=1; c<=N-1; ++c){
  //     for (ll a=1; a*a<=c; ++a){
  //         if(c%a==0) {
  //             res++;
  //             if (c/a!=a) res++;
  //         }
  //     }
  // }
  for (int a = 1; a * a <= N - 1; ++a) {
    // cout << a << " ";
    ll s = (N - 1) / a - (a);
    // cout << s << " " << endl;
    res += 2 * s;
    res++;
  }
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1 << 29;
using Graph = vector<vector<int>>;
int main() {
  ll N;
  cin >> N;
  ll res = 0;
  for (ll c = 1; c <= N - 1; ++c) {
    for (ll a = 1; a * a <= c; ++a) {
      if (c % a == 0) {
        res++;
        if (c / a != a)
          res++;
      }
    }
  }
  cout << res << 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;
typedef long long ll;
ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int sum = 0;
  int sum1 = 0;
  for (int i = 1; i < n; i++) {
    int a = n - i;
    sum1 = 0;
    int k = 0;
    for (int j = 1; j * j <= a; j++) {
      if (a % j == 0)
        sum1 += 2;
      k = j;
    }
    if (a == k * k)
      sum1 -= 1;
    sum += sum1;
  }
  cout << sum;
}

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;
ll mod = 1e9 + 7;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int num = n - i;
    float sq = sqrt(num);
    for (int j = 1; j <= sq; ++j) {
      if (num % j == 0) {
        if (j == sq) {
          ++ans;
        } else {
          ans += 2;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

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>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

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

  for (int c = 1; c < n; c++) {
    int num = n - c;
    for (int i = 1; i <= sqrt(num); ++i) {
      if (num % i == 0)
        if (num / i == i) {
          ans++;
        } else {
          ans++;
          ans++;
        }
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
// vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main() {
  long long int n;
  cin >> n;
  long long int res = 0;

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

  /*for(long long int i = 1; i < n; i++){// c = i;
      for(long long int j = 1; j*j <= n - i; j++){
          if((n - i)%j == 0){
              if(j == (n - i) / j){
                  res = res + 1;
              }else{
                  res = res + 2;
              }
          }
      }
  }*/
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main() {
  long long int n;
  cin >> n;
  long long int res = 0;
  // cの候補が1から

  for (long long int i = 1; i < n; i++) { // c = i;
    for (long long int j = 1; j * j <= n - i; j++) {
      if ((n - i) % j == 0) {
        if (j == (n - i) / j) {
          res = res + 1;
        } else {
          res = res + 2;
        }
      }
    }
  }
  cout << res << endl;
}