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

#include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int, int>

std::vector<ll> Eratosthenes(const ll N) {
  std::vector<ll> P(N + 1, 2);
  P[1] = 1;
  for (ll i = 2; i <= N; i++) {
    for (ll j = 2; i * j <= N; j++) {
      P[i * j]++;
    }
  }
  return P;
}
int main() {
  int N;
  cin >> N;
  ll retval = 0;
  auto v = Eratosthenes(N);
  rep(i, N + 1) {
    if (i == 0)
      continue;
    retval += i * v[i];
  }
  cout << retval << endl;
  // cout << fixed << setprecision(10);

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int, int>

unordered_map<ll, int> prime_factor(ll n) {
  unordered_map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  int N;
  cin >> N;
  ll retval = 0;
  for (int i = 1; i <= N; i++) {
    auto d = prime_factor(i);
    int cnt = 1;
    for (auto p : d) {
      cnt *= p.second + 1;
    }
    // cout << cnt << endl;
    retval += i * cnt;
  }
  cout << retval << endl;

  // cout << fixed << setprecision(10);

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

#include <fstream>
#include <iostream>
#include <vector>

#define N 10000001
using namespace std;

vector<int> v(N, 0);

void solve(int n) {
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      v[j]++;

  return;
}

using namespace std;

int main() {

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

  long long ans = 0;

  for (int i = 1; i <= n; i++) {
    ans += ((long long)v[i]) * i;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define FOR(a) for (int i = 1; i <= a; i++)

int main() {
  // freopen("in.txt","r",stdin);
  long long n, m, k, temp = 0;
  cin >> n >> m >> k;

  vector<long long> vn;
  vector<long long> vm;
  long long ans = 0;

  vn.push_back(0);
  vm.push_back(0);

  FOR(n) {
    cin >> temp;

    if (ans + temp > k)
      continue;
    ans += temp;
    vn.push_back(ans);
  }

  ans = 0;

  FOR(m) {
    cin >> temp;

    if (ans + temp > k)
      continue;
    ans += temp;
    vm.push_back(ans);
  }

  int mainans = 0;

  // cout<<" value of k "<<k<<endl;

  for (int i = 0; i < vn.size(); i++) {

    long long tem2 = k - vn[i];

    auto it = lower_bound(vm.begin(), vm.end(), tem2);
    int dis = distance(vm.begin(), it);
    if (tem2 != *it)
      dis--;

    // if(dis<0)dis++;
    mainans = max(mainans, i + dis);
    // cout<<endl;
  }
  cout << mainans << endl;

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

#include <bits/stdc++.h>
#define ll long long
#define mod 838627288460106
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

using namespace std;

int main() {
  fast_io ll n, j, ans = 0;
  cin >> n;
  for (j = 1; j <= n; j++) {
    ans += j * (n / j) * (n / j + 1) / 2;
    ans %= mod;
  }
  cout << ans % mod << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define mod 838627288460106
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

using namespace std;
ll countDivisors(ll n) {
  ll i, cnt = 0;
  for (i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;

      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int main() {
  fast_io ll n, j, ans = 0;
  cin >> n;
  for (j = 1; j <= n; j++) {
    ans += (j * countDivisors(j));
    ans %= mod;
  }
  cout << ans % mod << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void xin() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int f[100005] = {0};
void findDivisors(ll div[], int n) {

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

    for (ll j = 1; j * i <= n; j++)
      div[i * j]++;
  }
}

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

  ll n;
  cin >> n;
  ll ans = 0;
  ll div[n + 1] = {0};
  findDivisors(div, n);
  for (int i = 1; i <= n; i++) {
    ans += i * div[i];
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int divCount(int n) {
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (int p = 2; p * p < n; p++)
    if (hash[p] == true)
      for (int i = p * 2; i < n; i += p)
        hash[i] = false;

  int total = 1;
  for (int p = 2; p <= n; p++) {
    if (hash[p]) {
      int count = 0;
      if (n % p == 0) {
        while (n % p == 0) {
          n = n / p;
          count++;
        }
        total = total * (count + 1);
      }
    }
  }
  return total;
}
int main() {
  int n;
  cin >> n;
  int i;
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    ans += i * divCount(i);
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plii pair<ll, pii>
#define vi vector<int>
#define vii vector<vector<int>>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i, b, n) for (int i = b; i < n; ++i)
#define rev_loop(i, b, n) for (int i = b; i >= n; --i)
#define fio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int main() {
  fio;
  ll n;
  cin >> n;
  vector<ll> a(1e7 + 1, 1);

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

  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    res += i * a[i];
  }
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plii pair<ll, pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i, b, n) for (int i = b; i < n; ++i)
#define rev_loop(i, b, n) for (int i = b; i >= n; --i)
#define fio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int main() {
  fio;
  ll n;
  ll ans = 0;
  cin >> n;
  loop(j, 1, n + 1) {
    ll p = j, k = 0;
    for (int i = 1; i * i <= p; i++) {
      if (p % i == 0) {
        if (p / i != i)
          k += 2;
        else
          k += 1;
      }
    }
    ans += (p * k);
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define l unsigned long long int

int main() {
  l n;
  cin >> n;
  l ar[n + 1] = {0};
  for (l i = 1; i <= n; i++) {
    for (l j = i; j <= n; j += i) {
      ar[j]++;
    }
  }
  l sum = 0;
  for (l i = 1; i <= n; i++) {
    sum += (i * ar[i]);
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define l unsigned long long int

int divCount(int n) {
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (int p = 2; p * p < n; p++)
    if (hash[p] == true)
      for (int i = p * 2; i < n; i += p)
        hash[i] = false;

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

int main() {
  int n;
  cin >> n;
  l sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * divCount(i));
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> v(10000001, 1);
  for (int i = 2; i < 10000001; ++i) {
    int a = i;
    while (a <= 10000000) {
      ++v[a];
      a += i;
    }
  }

  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    ret += (long long)i * (long long)v[i];
  }
  cout << ret << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long n, m, k;
  cin >> n >> m >> k;

  vector<long long> av(n);
  for (auto &a : av) {
    cin >> a;
  }
  vector<long long> bv(m);
  for (auto &b : bv) {
    cin >> b;
  }

  long long ret = 0;
  {
    long long ai = 0;
    long long bi = 0;
    long long c = 0;

    while (c <= k) {
      if (ai < n) {
        c += av[ai++];
      } else {
        break;
      }
    }

    while (c <= k) {
      if (bi < m) {
        c += bv[bi++];
      } else {
        break;
      }
    }

    if (c <= k) {
      cout << n + m << endl;
      return 0;
    }

    while (0 < ai) {
      c -= av[--ai];
      if (k < c) {
        continue;
      }

      while (c <= k) {
        if (bi < m) {
          c += bv[bi++];
        } else {
          break;
        }
      }

      if (c <= k) {
        ret = max(ai + bi, ret);
      } else {
        ret = max(ai + bi - 1, ret);
      }
    }
  }

  swap(n, m);
  av.swap(bv);

  {
    long long ai = 0;
    long long bi = 0;
    long long c = 0;

    while (c <= k) {
      if (ai < n) {
        c += av[ai++];
      } else {
        break;
      }
    }

    while (c <= k) {
      if (bi < m) {
        c += bv[bi++];
      } else {
        break;
      }
    }

    if (c <= k) {
      cout << n + m << endl;
      return 0;
    }

    while (0 < ai) {
      c -= av[--ai];
      if (k < c) {
        continue;
      }

      while (c <= k) {
        if (bi < m) {
          c += bv[bi++];
        } else {
          break;
        }
      }

      if (c <= k) {
        ret = max(ai + bi, ret);
      } else {
        ret = max(ai + bi - 1, ret);
      }
    }
  }

  cout << ret << endl;

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
// const long long MOD = 998244353;

using namespace std;

void solve() {
  int n;
  scanf("%d", &n);

  ll ans = 0;
  int i, j;
  for (i = 1; i <= n; i++) {
    int m = n / i;
    ans += (ll)i * m * (m + 1) / 2;
  }
  printf("%lld\\n", ans);
  return;
}

int main(int argc, char *argv[]) {
#if 1
  solve();
#else
  int T;
  scanf("%d", &T);
  int t;
  for (t = 0; t < T; t++) {
    // printf("Case #%d: ", t+1);
    solve();
  }
#endif
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
// const long long MOD = 998244353;

using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b; // Be careful not to overflow
}

vector<int> pp;
void preparePrime(int maxp) {
  int i;
  vector<int> a(maxp + 1);
  for (i = 2; i <= maxp; i++) {
    int k = i + i;
    while (k <= maxp) {
      a[k] = 1;
      k += i;
    }
  }
  for (i = 2; i <= maxp; i++) {
    if (a[i] == 0)
      pp.push_back(i);
  }
  return;
}

void decompositPrime(ll a, vector<pair<ll, ll>> &vv) {
  int i;
  for (i = 0; i < (int)pp.size(); i++) {
    int count = 0;
    while (a % pp[i] == 0) {
      a /= pp[i];
      count++;
    }
    if (count > 0)
      vv.push_back(make_pair(pp[i], count));
    if (a == 1)
      break;
  }
  if (a > 1) {
    vv.push_back(make_pair(a, 1));
  }

  return;
}

void solve() {
  preparePrime(10000);
  int n;
  scanf("%d", &n);

  ll ans = 0;
  int i, j;
  for (i = 1; i <= n; i++) {
    vector<pair<ll, ll>> vv;
    decompositPrime(i, vv);
    ll ans0 = 1;
    for (j = 0; j < (int)vv.size(); j++) {
      ans0 *= (vv[j].second + 1);
    }
    ans += i * ans0;
  }
  printf("%lld\\n", ans);
  return;
}

int main(int argc, char *argv[]) {
#if 1
  solve();
#else
  int T;
  scanf("%d", &T);
  int t;
  for (t = 0; t < T; t++) {
    // printf("Case #%d: ", t+1);
    solve();
  }
#endif
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
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++;
    }
  }
}

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 n;
  cin >> n;
  long s = 0;
  for (long j = 1; j <= n; j++) {
    long x = countDivisors(j);
    s += j * x;
  }
  cout << s;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

  vector<int> f(n + 1);

  for (ll i = 1; i <= n; i++) {
    ll num = i;
    while (num <= n) {
      f[num]++;
      num += i;
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++)
    ans += f[i] * i;
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

// https://qiita.com/EqualL2/items/0964832dd7929d4004ad
std::vector<bool> IsPrime;

void sieve(size_t max) {
  if (max + 1 > IsPrime.size()) {  // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

vector<int> PrimeList;

void makelist(size_t max) {
  for (size_t i = 2; i < max; i++) {
    if (IsPrime[i])
      PrimeList.push_back(i);
    // cout << i << endl;
  }
}

ll f(int x) {
  map<int, ll> mp;
  for (auto p : PrimeList) {
    while (x % p == 0) {
      mp[p]++;
      x /= p;
    }
  }
  ll res = 1;
  for (auto m : mp)
    res *= (m.second + 1);
  return res;
}

int main() {

  int n;
  cin >> n;

  size_t N = 10000000;
  sieve(N);
  makelist(N);

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * f(i);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld", &n)
#define sf2(n, m) scanf("%lld %lld", &n, &m);
#define sf3(n, m, p) scanf("%lld %lld %lld", &n, &m, &p);
#define pf1(n) printf("%lld\\n", n);
#define mem(a, b) memset(a, b, sizeof(a))
#define en cout << endl;
#define pb push_back
#define fi first
#define se second
#define coy cout << "YES" << endl;
#define con cout << "NO" << endl;
#define f(a, b) for (ll i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pi pair<ll, ll>
#define br break;
#define i64 long long
#define PI 3.1415926535897932384626433832795

int main() {
  ll t, n, g, k, m, mx = 0, mn = 1e9, c, res, c1, x, y, w, z, c2;
  ci >> n;
  ll ab[n + 1];
  mem(ab, 0);
  f(1, n + 1) {
    for (ll j = i; j < n + 1; j += i)
      ab[j]++;
  }
  res = 0;
  f(1, n + 1) { res += i * ab[i]; }
  co << res;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld", &n)
#define sf2(n, m) scanf("%lld %lld", &n, &m);
#define sf3(n, m, p) scanf("%lld %lld %lld", &n, &m, &p);
#define pf1(n) printf("%lld\\n", n);
#define mem(a, b) memset(a, b, sizeof(a))
#define en cout << endl;
#define pb push_back
#define fi first
#define se second
#define coy cout << "YES" << endl;
#define con cout << "NO" << endl;
#define f(a, b) for (ll i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pi pair<ll, ll>
#define br break;
#define i64 long long
#define PI 3.1415926535897932384626433832795
vector<pi> fact;

void factorize(long long n) {
  int count = 0;

  while (!(n % 2)) {
    n >>= 1;
    count++;
  }
  if (count)
    fact.pb({2, count});
  for (long long i = 3; i <= sqrt(n); i += 2) {
    count = 0;
    while (n % i == 0) {
      count++;
      n = n / i;
    }
    if (count)
      fact.pb({i, count});
  }
  if (n > 2)
    fact.pb({n, 1});
}
int main() {
  ll t, n, g, k, m, mx = 0, mn = 1e9, c, res, c1, x, y, w, z, c2;
  ci >> n;
  res = 0;
  for (ll i = 1; i <= n; i++) {
    ll cnt = 0;
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (j == i / j)
          cnt++;
        else
          cnt += 2;
      }
    }
    res += i * cnt;
  }
  co << res;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int temp = n / i;
    int sum = (temp + 1) * temp / 2;
    ans += i * sum;
  }
  cout << ans << endl;
}
int32_t main() {
  rapido;
  int t;
  // cin>>t;
  t = 1;
  while (t--)
    solve();
}

Error: TLE

Fixed submission:

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

int find(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;
}
int32_t main() {
  int n;
  cin >> n;
  int ans = 0;

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

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    ll a = n / i;
    sum += i * a * (a + 1) / 2;
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

ll yk(ll x) {
  ll yks = 1;
  for (ll i = 2; i <= sqrt(x); i++) {
    ll cnt = 0;
    while (x % i == 0) {
      cnt++;
      x /= i;
    }
    yks *= (cnt + 1);
    if (x == 1)
      break;
  }
  if (x != 1)
    yks *= 2;
  return yks;
}

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

#include <iostream>
#include <vector>

int main(void) {
  long long int n;
  std::cin >> n;
  std::vector<long long int> yn(n);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j = j + i) {
      yn[j]++;
    }
  }

  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += i * yn[i];
  }

  std::cout << sum << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> yn(n);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      if (j % i == 0)
        yn[j]++;
    }
  }

  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += i * yn[i];
  }

  std::cout << sum << std::endl;

  return 0;
}