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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll i, j, n;
  cin >> n;
  ll ans = (n * (n + 1)) / 2;
  for (i = 2; i <= n; i++) {
    j = 1;
    while (i * j <= n)
      ans += (i * j), j++;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll i, j, n;
  cin >> n;
  ll ans = 1;
  for (i = 2; i <= n; i++) {
    ll cur = 2;
    for (j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        if (j * j == i)
          cur++;
        else
          cur += 2;
      }
    }
    ans += (i * cur);
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  ll a, b, c, h, i, j, k, l, m, n, x, y;
  ll ans = 0;
  string s;
  cin >> n;

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

    ans += (n - (n % i) + i) * (n / i) / 2;
  }

  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  ll a, b, c, h, i, j, k, l, m, n, x, y;
  ll ans = 0;
  string s;
  cin >> n;

  for (a = 1; a <= n; a++) {
    ll fk = 0;
    for (i = 1; i * i <= a; i++) {
      if ((a % i) == 0) {
        fk++;
        if (a / i != i)
          fk++;
      }
    }
    // cout << "fk:" << fk << endl;
    ans += a * fk;
  }

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

#include <algorithm>
#include <bitset>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      sum += j;
    }
    // cout << sum << endl;
  }
  cout << sum << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

const int N = 10000001;
int mind[N];
vector<int> pr;

void build_sieve() {
  mind[0] = mind[1] = 1;
  for (int i = 2; i < N; ++i) {
    if (mind[i] == 0) {
      pr.push_back(i);
      mind[i] = i;
    }
    for (int j = 0; j < int(pr.size()) && pr[j] <= mind[i] && i * pr[j] < N;
         ++j) {
      mind[i * pr[j]] = pr[j];
    }
  }
}

int a[10000001];
long long int foo(int n) {
  int ans = 1;
  vector<int> x(n + 1);
  int num = n; // 素因数分解する変数num

  int cnt = 0;
  for (int i = 2; i <= n; i++) {
    // for (int i = n-1; i >= 2; i--) {
    // cout << "Check:" << i << endl;
    while (num % i == 0) { // 素数で割り切れなくなるまで割っていく
      x.at(i)++;           // 割った個数を配列に足す
      num /= i;
      // cout << i << " * ";
      /*
      if(a[i] != 0){

          if(num%i == 0){
              cout << "* " << a[i];
              x.at(i) = a[i];

          }else{
              cout << "* " << a[i]-1;
              x.at(i) = 1;
          }
          break;
      }
      */
    }
    // if(x.at(i) != 0) cout << endl;
  }

  for (int i = 2; i <= n; i++) {
    ans *= x.at(i) + 1; // それぞれを+1して掛けていく
  }
  return ans;
}
int main() {
  build_sieve();

  int n;
  cin >> n;
  for (int i = 0; i <= n; i++)
    a[i] = 0;

  long long int s = 0;
  for (int i = 1; i <= n; i++) {
    // cout << ">> " << i << endl;
    if (i == mind[i]) {
      if (i == 1)
        a[i] = 1;
      else
        a[i] = 2;
    } else {
      a[i] = foo(i);
    }
    // cout << i << ":" << a[i] << endl;
    s += i * a[i];
    // cout << s << endl;
  }
  cout << s << endl;

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

// 171

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long int n, sum = 0, buf = 0;
  cin >> n;

  for (long long int j = 1; j <= n; j++) {
    buf = j;
    while (buf <= n) {
      sum += buf;
      buf += j;
    }
  }
  cout << sum << endl;
}


Error: TLE

Fixed submission:

// 171

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long int n, sum = 0;
  cin >> n;
  vector<long long int> v(n, -1);
  for (long long int i = 1; i <= n; i++) {
    long long int buf = 0, j = 1;
    for (; j < sqrt(i); j++) {
      if (i % j == 0) {
        buf += 2;
      }
    }
    if (j == sqrt(i))
      buf++;
    // v.at(i-1) = buf;
    sum += i * buf;
  }

  // for(auto num: v){
  //     cout << num << endl;
  // }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long int n;
long long s;
int main() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    long long int q = n / i;
    s += i * q * (q + 1) / 2;
  }
  cout << s;
}


Error: TLE

Fixed submission:

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

long long int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int main() {
  long long int n, s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    s += i * countDivisors(i);
  cout << s;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    ll k = n / i;
    ans += i * k * (k + 1) / 2;
  }
  cout << ans << endl;
}

Error: -8

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    ll k = n / i;
    ans += i * k * (k + 1) / 2;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  const ll MAX = 10000005;
  static ll factor[MAX] = {};
  for (ll i = 1; i <= N; i++) {
    ll index = i;
    while (index < MAX) {
      factor[index]++;
      index += i;
    }
    ans += i * factor[i];
    // cout << i << " " << f(i) << endl;
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using std::cin;
using std::cout;
using std::endl;
using std::vector;

ll f(ll N) {
  vector<std::pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  ll ans = 1;
  for (auto p : res)
    ans *= p.second + 1;
  return ans;
}

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 0; i <= N; i++) {
    ans += i * f(i);
    // cout << i << " " << f(i) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL)
typedef long long ll;
#define trace(x) cerr << #x << ": " << x << endl;
#define rep(i, a) for (ll i = 0; i < a; i++)
#define pb push_back
#define vl vector<ll>
#define rep(i, a) for (ll i = 0; i < a; i++)
const int N = 1e7 + 5;
ll c[N];
int main() {
  fast;
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 0; j <= n; j += i) {
      c[j]++;
    }
  }
  ll sum = 0;
  for (ll i = 1; i <= n; i++)
    sum += i * c[i];
  cout << sum;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL)
typedef long long ll;
#define trace(x) cerr << #x << ": " << x << endl;
#define rep(i, a) for (ll i = 0; i < a; i++)
#define pb push_back
#define vl vector<ll>
#define rep(i, a) for (ll i = 0; i < a; i++)
const int N = 1e7 + 5;
map<ll, ll> mp;
ll primeFactors(ll n) {
  mp.clear();
  ll res = 1;
  while (n % 2 == 0) {
    mp[2]++;
    n = n / 2;
  }
  if (mp[2])
    res *= (mp[2] + 1);
  for (int i = 3; i <= sqrt(n); i = i + 2) {

    while (n % i == 0) {
      mp[i]++;
      n = n / i;
    }
    if (mp[i])
      res *= (mp[i] + 1);
  }

  if (n > 2)
    mp[n]++;
  res *= (mp[n] + 1);
  return res;
}
int main() {
  fast;
  ll n;
  cin >> n;
  ll sum = 1;
  for (ll i = 2; i <= n; i++) {
    ll res = primeFactors(i);
    sum += i * res;
  }
  cout << sum;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

vector<ll> f(ll n) {
  vector<ll> v(n + 1, 1);

  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      v[j]++;
    }
  }

  return v;
}

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  vector<ll> v = f(n);

  for (int i = 1; i <= n; ++i) {
    res += (i * v[i]);
  }

  cout << res;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int f(int n) {
  vector<int> v(n + 1, 0);
  int count = 0;

  for (int i = 1; i <= n / 2; ++i) {
    if (v[i] == 0) {
      if (n % i == 0) {
        v[i] = 1, ++count;
        if (v[n / i] == 0)
          v[n / i] = 1, ++count;
      }
    }
  }
  return count;
}

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

  for (int i = 1; i <= n; ++i) {
    res += (i * f(i));
  }

  cout << res + 1;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

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

  cin >> n;

  for (int i = 1; i <= n; i++) {
    long long first = i;
    long long last = n - n % i;
    long long num = n / i;
    ans += (first + last) * num / 2;
  }

  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

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

int n, m, k;
long long a[200005];
long long b[200005];
long long suma[200005];
long long sumb[200005];

bool canread(int num) {
  bool ans = false;
  for (int i = 0; i <= num; i++) {
    int j = num - i;
    // Aからi冊 Bからj冊読めるか
    //  cout << "num" << num << "n" << n << "m" << m << "i" << i << "j" << j <<
    //  endl;
    if (n < i || m < j)
      continue;
    if (suma[i] + sumb[j] <= k) {
      ans = true;
      // cout << "ok" << endl;
      break;
    }
  }
  return ans;
}

int main() {
  cin >> n >> m >> k;
  rep(i, n) {
    cin >> a[i];
    suma[i + 1] = suma[i] + a[i];
  }
  rep(i, m) {
    cin >> b[i];
    sumb[i + 1] = sumb[i] + b[i];
  }

  int l = 0, r = n + m + 1;
  while (r - l > 1) {
    int c = (r + l) / 2;
    // cout << "[" << l << "," << r << "]" << c;
    if (canread(c))
      l = c;
    else
      r = c;
  }

  cout << l << endl;
  return 0;
}
Problem p02624 (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 P = pair<int, int>;
typedef long long ll;

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


Error: TLE

Fixed submission:

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

ll 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);
    }
  }
  return (ll)ret.size() * n;
}

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

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

Int N; //= 700000;
map<Int, Int> a;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Int n;
  cin >> n;
  N = n;
  Int ans = 0;
  for (Int i = 1; i <= n; i++) {
    Int x = (n / i);
    ans += (Int)(i * ((x) * (x + 1)) / 2);
  }
  // Int x = n/2;
  // ans+=(Int)((n*(n+1)/2)-(x*(x+1)/2));
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

Int N; //= 700000;
map<Int, Int> a;

void X() {
  for (int i = 1; i <= N; i++) {
    for (int j = 1; i * j <= N; j++) {
      a[i * j]++;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  N = n;
  X();
  Int ans = 0;
  for (Int i = 1; i <= n; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LL long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\\n", x)
#define plld(x) printf("%lld\\n", x)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL mod = 1e9 + 7;
const int maxn = 1e7 + 7;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);

LL a[maxn];

int main() {

#ifndef ONLINE_JUDGE
  //	freopen("in.txt", "r", stdin);
  //	freopen("out.txt", "w", stdout);
  long _begin_time = clock();
#endif

  rep(i, 1, maxn - 7) {
    for (int j = i; j <= maxn - 7; j += i) {
      a[j]++;
    }
  }
  int n;
  sd(n);
  LL ans = 0;
  rep(i, 1, n) { ans += i * a[i]; }
  plld(ans);

#ifndef ONLINE_JUDGE
  long _end_time = clock();
  // cout << "time = " <<  _end_time - _begin_time << endl;
#endif
  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LL long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\\n", x)
#define plld(x) printf("%lld\\n", x)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL mod = 1e9 + 7;
const int maxn = 1e7 + 7;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);

LL a[maxn];

int main() {

#ifndef ONLINE_JUDGE
  //	freopen("in.txt", "r", stdin);
  //	freopen("out.txt", "w", stdout);
  long _begin_time = clock();
#endif

  int n;
  sd(n);
  LL ans = 0;
  rep(i, 1, n) {
    LL res = 0;
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        res += 2;
        if (i / j == j)
          res--;
      }
    }
    ans += i * res;
  }
  plld(ans);

#ifndef ONLINE_JUDGE
  long _end_time = clock();
  // cout << "time = " <<  _end_time - _begin_time << endl;
#endif
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<ll> p(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / i; j++) {
      p[i * j - 1]++;
    }
  }
  ll ans = 0;
  rep(i, n) { ans += (i + 1) * p[i]; }
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<ll> p(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / i; j++) {
      p[i * j - 14]++;
    }
  }
  ll ans = 0;
  rep(i, n) { ans += (i + 1) * p[i]; }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define N 10000000
typedef long long ll;
vector<ll> v(N + 1);
int main() {
  // precalc();
  ll n;
  cin >> n;
  for (ll x = 1; x <= n; x++) {
    ll y = n / x;
    v[x] = (y * (y + 1) * x) / 2;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += v[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define N 10000000
typedef long long ll;
vector<ll> v(N + 1);
void precalc() {
  v[1] = 1;
  for (ll i = 2; i <= N; i++) {
    // cout<<i<<endl;
    ll flag = 0;
    ll cnt = 0;
    ll j;
    for (j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        ll temp = i;
        while (temp % j == 0) {
          cnt++;
          temp /= j;
        }
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      v[i] = 2;
    else {
      v[i] = v[i / j] * (cnt + 1) / cnt;
    }
  }
}
int main() {
  precalc();
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * v[i];
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ar array
#define pii pair<int, int>

const int N = 1e7 + 5;
int cnt[N];

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

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i)
      cnt[j]++;
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++)
    ans += 1ll * i * cnt[i];
  cout << ans << '\\n';
}

Error: TLE

Fixed submission:

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

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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans += 1ll * i * f(i);
  cout << ans << '\\n';
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  long long int N, i, j, ans = 0;
  cin >> N;
  vector<long long int> data(N + 1);
  for (i = 1; i <= N; i += 1) {
    data[i] = 1;
  }
  for (i = 2; i <= N; i += 1) {
    for (j = i; j <= N; j += i) {
      data[j] += 1;
    }
  }
  for (i = 1; i <= N; i += 1) {
    ans += i * data[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

// Function to count divisors
int countDivisors(int n) {
  if (n == 1)
    return 1;

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

  int a[n];
  SieveOfEratosthenes(n, prime, primesquare, a);

  int ans = 1;

  for (int i = 0;; i++) {
    if (a[i] * a[i] * a[i] > n)
      break;

    int cnt = 1;
    while (n % a[i] == 0) {
      n = n / a[i];
      cnt = cnt + 1;
    }
    ans = ans * cnt;
  }

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

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

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

  return ans;
}

int main() {
  long long int N, i, ans = 0;
  cin >> N;
  for (i = 1; i <= N; i += 1) {
    ans = ans + (i * countDivisors(i));
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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 ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

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

  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    ll x = n / i;
    res += x * (x + 1) * i / 2;
  }
  cout << res << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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 ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

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

  ll n;
  cin >> n;
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    ll x = n / x;
    res += (x + 1) * i / 2;
  }
  cout << res << endl;
  return 0;
}