alexjercan/bugnet huggingface dataset:
Problem p02624 (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<ll> num(N + 1);
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    for (ll j = i; j <= N; j = j + i) {
      num[j]++;
    }
    ans += i * num[i];
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

using ll = long long;

int main() {

  int N;
  cin >> N;

  vector<int> num(N + 1);
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) {
      if (j % i == 0) {
        num[j]++;
      }
    }
    ans += i * num[i];
  }

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

#include <iostream>
#define ll long long

using namespace std;

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      ans += j;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#define ll long long

using namespace std;

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

#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF ((1 << 30) - 1 + (1 << 30))
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)
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;
}

int main() {
  const int sz = 1e7;
  vector<int> bkt(sz + 1, 2);
  bkt[0] = 0;
  bkt[1] = 1;
  for (int i = 2; i <= sz / 2; ++i) {
    for (int j = i * 2; j < sz + 1; j += i) {
      ++bkt[j];
    }
  }
  int N;
  cin >> N;
  ll ans = 0;
  rep(i, N + 1) { ans += (ll)i * bkt[i]; }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF ((1 << 30) - 1 + (1 << 30))
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)
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;
}

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const double PI = acos(-1.0);

int gcd(int a, int b) {
  int c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

int N;
void input() { cin >> N; }

void solve() {
  ll ans = 0;
  for (int i = 1; i < N + 1; ++i) {
    int j = 1;
    while (i * j <= N) {
      ans += i * j;
      ++j;
    }
  }
  cout << ans << endl;
}

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

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const double PI = acos(-1.0);

int gcd(int a, int b) {
  int c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

int N;
vll f;
void input() { cin >> N; }

void solve() {
  f.assign(10000010, -1);
  f[1] = 1;
  for (int i = 2; i < N + 1; ++i) {
    map<int, int> M;
    int j = 2;
    int tmp_i = i;
    while (j <= tmp_i) {
      if (tmp_i % j == 0) {
        tmp_i /= j;
        M[j]++;
        continue;
      } else
        ++j;
    }
    f[i] = 1;
    for (auto p : M) {
      f[i] *= p.second + 1;
    }
  }
  ll ans = 0;
  for (int i = 1; +i < N + 1; ++i) {
    ans += i * f[i];
  }
  cout << ans << endl;
}

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

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)

main() {
  int n = 0;
  char c;
  while (1) {
    c = getwchar_unlocked();
    if (c != '\\n')
      n = n * 10 + c - '0';
    else
      break;
  }
  int sqrtN = sqrt(n);
  ll ans = 0;
  ll d = (ll)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
  rep2(i, 1, sqrtN) { ans += (i * (i + (n / i)) * ((n / i) + 1 - i)); }
  ans -= d;
  char wr[15];
  char *w = wr;
  while (ans) {
    *w = ans % 10 + '0';
    ans /= 10;
    w++;
  }
  while (1) {
    w--;
    putwchar_unlocked(*w);
    if (w == wr)
      break;
  }
}


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j = 0, p = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    j = n / i;
    p = p + (((j) * (j + 1)) / 2) * i;
  }
  cout << p << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

int main() {
  long long N;
  cin >> N;
  long long SUM = 0;
  for (long long i = 1; i < N + 1; i++) {
    long long counter = 0;
    long long check = 0;
    check = floor(N / i);
    SUM = SUM + i * ((1 + check) * check / 2);
    ;
  }

  cout << SUM << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  long long SUM = 0;
  for (long long i = 1; i < N + 1; i++) {
    long long counter = 0;
    for (long long j = 1; j < N + 1; j++) {
      if ((i % j) == 0) {
        counter++;
      }
    }
    SUM = SUM + i * counter;
  }
  cout << SUM << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  for (long long i = 1; i <= N; i++) {
    ans += ((1 + N / i) * (N / i) / 2) * i;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int M = 1;
  vector<long long> kosu(N, 1);
  vector<long long> so(500);
  so.at(0) = 2;

  for (int i = 2; i <= N; i++) {
    int L = i;
    for (int j = 0; j < M; j++) {
      if (L % so.at(j) == 0) {
        for (int k = 0; k < 23; k++) {
          if (L % so.at(j) == 0) {
            L /= so.at(j);
          } else {
            kosu.at(i - 1) *= k + 1;
            break;
          }
        }
      }
      if (L == 1) {
        break;
      }
      if (j == M - 1 && L > 1) {
        if (L <= 3162) {
          so.at(M) = L;
          M++;
        }
        kosu.at(i - 1) *= 2;
        break;
      }
    }
  }

  long long ans = 0;

  for (int i = 0; i < N; i++) {
    ans += kosu.at(i) * (i + 1);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> L(N + 1);
  // ll mid = N/2+1;
  for (ll i = 1; i < N + 1; i++) {
    for (ll j = 0; j < N + 1; j += i) {
      L[j]++;
    }
  }
  ll ans = 0;
  rep(i, N + 1) ans += i * L[i];

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<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});
  return res;
}

int main() {
  long long N;
  cin >> N;
  ll ans = 1;
  for (ll i; i < N - 1; i++) {
    const auto &pf = prime_factorize(i + 2);
    long long res = 1;
    for (auto p : pf)
      res *= p.second + 1;
    long long ans1 = res * (i + 2);
    // if(i > 4000000) cout << ans1 << endl;
    ans += ans1;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>

#define ll long long

using namespace std;

void solve() {
  ll n;
  cin >> n;
  ll res = 0;

  for (ll i = 1; i <= n; i++) {
    ll j = n / i;
    res += i * (j * (j + 1)) / 2;
  }
  cout << res << endl;
}

int main() {

  // int T;
  // cin >> T;
  // while(T--) {
  // solve();
  // }
  solve();

  return 0;
};


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>

#define ll long long

using namespace std;

const int N = 1e7 + 5;
int prime[N] = {0}, num_prime = 0;
int isNotPrime[N] = {1, 1};

// N is initialized above, adjust before use
void label_prime() {
  for (int i = 2; i < N; i++) {
    if (!isNotPrime[i]) {
      prime[num_prime++] = i;
    }
    for (int j = 0; j < num_prime && i * prime[j] < N; j++) {
      isNotPrime[i * prime[j]] = 1;
      // early stop when i divides current prime[j]
      if (!(i % prime[j])) {
        break;
      }
    }
  }
  return;
}

void solve() {
  int n;
  cin >> n;
  ll res = 1;
  label_prime();
  for (int i = 2; i <= n; i++) {
    if (!isNotPrime[i]) {
      // cout << i << endl;
      res += 2ll * i;
    } else {
      int c = 2;
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) {
          c += 2;
          if (j * j == i) {
            c--;
          }
        }
      }
      res += (ll)c * i;
    }
  }
  cout << res << endl;
}

int main() {

  // int T;
  // cin >> T;
  // while(T--) {
  // solve();
  // }
  solve();

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = a; i >= b; i--)
#define maxN 200005
#define inf (int)1e9
#define mode (int)1000000007
#define ll long long

using namespace std;

int n;
int f[10000005];

void enter() {
  scanf("%d", &n);
  FOR(i, 1, n)
  FOR(j, 1, n / i) {
    int k = i * j;
    f[k]++;
  }
}

void solve() {
  ll ans = 0;
  FOR(i, 1, n)
  ans += 1ll * i * f[i];
  printf("%lld", ans);
}

int main() {
  // freopen("main.inp", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  enter();
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = a; i >= b; i--)
#define maxN 200005
#define inf (int)1e9
#define mode (int)1000000007
#define ll long long

using namespace std;

int n;
map<int, int> f;

void enter() {
  scanf("%d", &n);
  FOR(i, 1, n)
  FOR(j, 1, n / i) {
    int k = i * j;
    f[k]++;
  }
}

void solve() {
  ll ans = 0;
  FOR(i, 1, n)
  ans += 1ll * i * f[i];
  printf("%lld", ans);
}

int main() {
  // freopen("main.inp", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  enter();
  solve();
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

ll nod[10000000 + 100] = {0};

void NOD(ll n) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i)
      nod[j]++;
  }
}

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

  NOD(N);

  ll sum = 0;
  for (ll i = 1; i <= N; i++) {
    sum += i * nod[i];
  }
  cout << sum << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

int nod[10000005];

ll NOD(ll n) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i)
      nod[j]++;
  }
}

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

  NOD(n);

  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    sum += i * nod[i];
  }
  cout << sum << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define bn "\\n"

const ll N = 1e7 + 5;
std::vector<ll> prime;
ll sol[N];

void save() {
  //	std::fill (sol, sol + n, false);
  for (ll i = 2; i < N; ++i) {
    //	if (sol[i]==0) prime.push_back (i);
    for (ll j = 2; i * j < N; ++j)
      sol[i * j]++;
  }
  for (ll i = 1; i < N; i++) {
    sol[i]++;
    sol[i]++;
    sol[i] = sol[i - 1] + (sol[i] * i);
  }
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  save();
  ll n;
  cin >> n;
  cout << (sol[n] - 1) << bn;

  return 0;
}

Error: TLE

Fixed submission:

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

ll countDivisors(int 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(0);

  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * countDivisors(i);
  }
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int k;
  cin >> k;
  ll ans = 0;
  for (int i = 1; i <= k; i++) {
    int num = k / i;
    ll temp = 2 * i + (num - 1) * i;
    ans += (num * temp / 2);
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> sieve;
ll dp(int num) {
  //	int var=
  if (num == 1)
    return 1;
  if (sieve[num] == 1)
    return 2;
  ll pr = 1;
  for (int i = sieve[num]; i * i <= num; i++) {
    int cnt = 0;
    while (num % i == 0) {
      cnt++;
      num /= i;
    }

    pr *= (cnt + 1);
  }
  if (num > 1)
    pr *= 2;
  return pr;
}
int main() {
  int k;
  cin >> k;
  sieve.resize(k + 1, 1);
  for (int i = 2; i <= k; i++) {
    if (sieve[i] > 1)
      continue;
    for (int j = 2; i * j <= k; j++) {
      if (sieve[i * j] == 1)
        sieve[i * j] = i;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= k; i++) {
    //	cout<<i<<" "<<dp(i)<<"\\n";
    ans = ans + i * dp(i);
  }
  //	cout<<sieve[k]<<"\\n";
  cout << ans;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void div(int a) {

  int division[a + 1];
  memset(division, 0, sizeof division);

  for (int i = 1; i <= a; i++) {
    for (int j = 1; j * i <= a; j++) {
      division[i * j]++;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= a; i++) {
    sum = sum + 1LL * i * division[i];
  }
  cout << sum << "\\n";
}

int main() {
  int x;
  cin >> x;
  div(x);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int div(int a) {
  int temp = 0;
  for (int i = 1; i <= a; i++) {
    if (a % i == 0) {
      temp += 1;
    }
  }
  return temp;
}

int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum + 1LL * (div(i) * i);
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, i, j;
long long ans;

int main() {
  scanf("%d", &n);
  vector<long long> a(n + 1);
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  for (i = 1; i <= n; i++) {
    ans += i * a[i];
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

long long i, j, limit, n, c, ans;

int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    limit = ceil((double)i);
    for (j = 1, c = 1; j <= limit && j != i; j++) {
      if (i % j == 0)
        c++;
    }
    ans += i * c;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

  vector<ll> num(N + 1, 1);
  ll ans = 1;
  for (int n = 2; n <= N; ++n) {
    for (int ii = n; ii <= N; ii += n) {
      num[ii]++;
    }
    ans += n * num[n];
  }

  cout << ans << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

  // まず素数を見つける
  vector<bool> is_prime(N + 1, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i <= N; ++i) {
    if (!is_prime[i])
      continue;
    for (int j = i * 2; j <= N; j += i) {
      is_prime[j] = false;
    }
  }

  ll ans = 0;
  for (int n = 1; n <= N; ++n) {
    ll num = 0;
    if (n == 1) {
      num = 1;
    } else if (is_prime[n]) {
      num = 2;
    } else {
      for (ll ii = 1; ii * ii <= n; ++ii) {
        if (n % ii == 0) {
          num++;
          if (n / ii != ii) {
            num++;
          }
        }
      }
    }
    ans += n * num;
  }

  cout << ans << "\\n";

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

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

int main() {
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int terms = n / i;
    long long int sum = terms * (i + terms * i) / 2;
    ans = ans + sum;
  }
  cout << ans;
}


Error: TLE

Fixed submission:

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

int main() {
  unsigned long long int n;
  cin >> n;
  unsigned long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i % j == 0)
        ans = ans + i;
    }
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(), v.end()
#define forn(i, n) for (ll i = 0; i < (ll)n; i++)
#define fi first
#define se second

int main() {
  ll n, y;
  cin >> n;
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    y = n / i;
    res += i * y * (y + 1) / 2;
  }

  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(), v.end()
#define forn(i, n) for (ll i = 0; i < (ll)n; i++)
#define fi first
#define se second

int n;
vector<char> prime;

int count(int x) {
  int total = 1;
  for (int p = 2; p <= x; p++) {
    if (prime[p]) {
      int cnt = 0;
      if (x % p == 0) {
        while (x % p == 0) {
          x /= p;
          cnt++;
        }
        total *= (cnt + 1);
      }
    }
  }
  return total;
}

int main() {
  cin >> n;
  prime.resize(n + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (prime[i]) {
      for (int j = i * 2; j <= n; j += i)
        prime[j] = false;
    }
  }
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    res += i * count(i);
  }
  cout << res << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost()                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

///---DATA TYPE---///
typedef long long ll;

int main() {
  Boost();

  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
      ll cntMultipleOfiLessThanN = floor((n * 1.0) / (i * 1.0));
      ll tmp = (cntMultipleOfiLessThanN * (cntMultipleOfiLessThanN + 1) * i);
      ans += (tmp / 2);
    }
    cout << ans << endl;
  }
  return 0;
}

///---hints:----///
/*
For a positive integer j, we define g(j) as the sum of multiples of j that does
not exceed N. Find sum[g(j);j=1...N],This g(X) is a sum of an arithmetic
progression,and can be calculated faster than f(X). Specifically, let
Y=floor(N/X)(the maximum integer that does not exceed N/X), then
g(X)=X+2X+...+YX=(1+2+...+Y)X=Y(Y+ 1)X/2, so by using this formula, the problem
can be solved in a total of O(N) time.
*/


Error: TLE

Fixed submission:

///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost()                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

///---DATA TYPE---///
typedef long long ll;

map<ll, ll> d;
ll ans = 0;
void numOfDiv(ll n) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      d[j]++;
      // cout<<d[j]<<endl;
    }
  }
}
int main() {
  Boost();

  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    numOfDiv(n);
    for (ll i = 1; i <= n; i++) {
      ans += (i * d[i]);
    }
    cout << ans << endl;
  }
  return 0;
}