alexjercan/bugnet huggingface dataset:
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;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; ++i) {
    for (ll j = i; j <= N; j += i) {
      ans += j;
    }
  }
  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;
typedef long long ll;

vector<bool> isp(10000007, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i = 2; i * i <= 10000006; i++) {
    if (isp[i])
      for (int j = 2; i * j <= 10000006; j++)
        isp[i * j] = false;
  }
}

// 約数の個数を数える
ll count_divisors(long long N) {
  int ret = 0;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      ret++;
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        ret++;
    }
  }
  return ret;
}

int main() {
  ll N;
  cin >> N;
  sieve();
  ll ans = 1;
  for (ll i = 2; i <= N; ++i) {
    if (isp[i])
      ans += i * 2;
    else
      ans += (i * count_divisors(i));
    //    cout << i << " : " << count_divisors(i) << " :" << ans <<endl;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
  ll n;
  cin >> n;

  ll ans = 0;
  rep3(i, 1, n) {
    ll cnt = n / i;
    ll sum = (cnt + 1) * cnt / 2;
    ans += i * sum;
  }

  cout << ans << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vll prime_list;

void make_prime_list(ll n) {
  vector<bool> isprime(n + 1, true);
  isprime[0] = false;
  isprime[1] = false;

  for (ll i = 2; i * i <= n; i++) {
    if (!isprime[i])
      continue;
    for (ll j = i * 2; j <= n; j += i) {
      isprime[j] = false;
    }
  }

  rep3(i, 1, n) if (isprime[i]) prime_list.pb(i);
  return;
}

ll num_of_div(ll n) {
  ll ans = 1;
  if (n == 1)
    return ans;
  for (auto i : prime_list) {
    if (i * i > n)
      break;
    ll cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt)
      ans *= (cnt + 1);
  }
  if (n != 1)
    ans *= 2;
  return ans;
}

void Main() {
  ll n;
  cin >> n;
  make_prime_list(n);

  /*
  cout << prime_list.size() << endl;
  for(auto p : prime_list){
      cout << p << " ";
  }
  cout << endl;
  //*/

  //*
  ll ans = 0;
  rep3(i, 1, n) {
    ans += i * num_of_div(i);
    // cout << i << " " << ans << endl;
  }

  cout << ans << endl;
  //*/
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie();                                                                   \\
  cout.tie();

#define MAXX 500005
#define PI 3.14159265358979323846264338327950

#define ll long long int
#define mod 1000000007
ll t, ans, poi;
ll a[MAXX], b[MAXX], ans1;
ll divis(ll n) {
  poi = 0;
  poi = (n * (n + 1)) / 2;
  return (n * (n + 1)) / 2;
}
int main() {
  FAST;
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ans += i * divis(n / i);
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie();                                                                   \\
  cout.tie();

#define MAXX 500005
#define PI 3.14159265358979323846264338327950

#define ll long long int
#define mod 1000000007
ll t, ans, poi;
ll a[MAXX], b[MAXX], ans1;
ll divis(ll n) {
  poi = 0;
  if (floor(sqrt(n)) == ceil(sqrt(n))) {
    poi++;
  }
  for (ll i = 1; i * i < n; i++) {
    if (n % i == 0) {
      poi += 2;
    }
  }
  return poi;
}
int main() {
  FAST;
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ans += divis(i) * i;
  }
  cout << ans;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
// Men at Work :)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

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

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


Error: TLE

Fixed submission:

// Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
// Men at Work :)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void cpp() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
ll MAXN;

void sieve(vector<ll> &primes) {
  primes[1] = 1;
  for (ll i = 2; i < MAXN; i++) {
    primes[i] = i;
  }
  for (ll i = 4; i < MAXN; i += 2) {
    primes[i] = 2;
  }
  for (ll i = 3; i * i < MAXN; i++) {
    if (primes[i] == i) {
      for (ll j = i * i; j < MAXN; j += i) {
        if (primes[j] == j) {
          primes[j] = i;
        }
      }
    }
  }
}

int main() {
  cpp();
  ll n;
  cin >> n;
  vector<ll> primes(n + 1);
  MAXN = n + 1;
  sieve(primes);
  unordered_map<ll, ll> mapp;
  mapp[1] = 1;
  for (ll i = 2; i <= n; i++) {
    unordered_map<ll, ll> mapptemp;
    ll temp = i;
    while (temp != 1) {
      mapptemp[primes[temp]]++;
      temp /= primes[temp];
    }
    ll tempAns = 1;
    for (auto &it : mapptemp) {
      tempAns *= (it.second + 1);
    }
    mapp[i] = tempAns;
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += (i * mapp[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const int MAX = 10000010;
bool IsPrime[MAX];
int MinFactor[MAX];
vector<int> preprocess(int n = MAX) {
  vector<int> res;
  for (int i = 0; i < n; ++i)
    IsPrime[i] = true, MinFactor[i] = -1;
  IsPrime[0] = false;
  IsPrime[1] = false;
  MinFactor[0] = 0;
  MinFactor[1] = 1;
  for (int i = 2; i < n; ++i) {
    if (IsPrime[i]) {
      MinFactor[i] = i;
      res.push_back(i);
      for (int j = i * 2; j < n; j += i) {
        IsPrime[j] = false;
        if (MinFactor[j] == -1)
          MinFactor[j] = i;
      }
    }
  }
  return res;
}

vector<pair<int, int>> prime_factor(int n) {
  vector<pair<int, int>> res;
  while (n != 1) {
    int prime = MinFactor[n];
    int exp = 0;
    while (MinFactor[n] == prime) {
      ++exp;
      n /= prime;
    }
    res.push_back(make_pair(prime, exp));
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  ll res = 0;
  preprocess();
  for (int x = 1; x <= n; x++) {
    auto pf = prime_factor(x);
    ll tmp = 1;
    for (auto p : pf) {
      tmp *= (p.second + 1);
    }
    res += tmp * x;
  }
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
unordered_map<ll, int> prime_factor(ll n) {
  unordered_map<ll, int> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}
int main() {
  int n;
  cin >> n;
  ll res = 0;
  for (int x = 1; x <= n; x++) {
    auto tmp = prime_factor(x);
    ll now = 1;
    for (auto e : tmp) {
      now *= ll(e.second + 1);
    }
    // cout << now << endl;
    res += now * x;
  }
  cout << res << endl;
  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 ans = 0;
  for (int k = 1; k <= n; k++) {
    ans += (double(k) / 2) * floor(n / k) * floor(1 + n / k);
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

long long divisors(int n) {

  long long prod = 1;
  int res = 0;
  while (n % 2 == 0) {
    res += 1;
    n /= 2;
  }
  prod *= (res + 1);

  for (int i = 3; i <= sqrt(n); i += 2) {
    res = 0;
    while (n % i == 0) {
      res += 1;
      n /= i;
    }
    prod *= (res + 1);
  }
  if (n > 1) {
    prod *= 2;
  }

  return prod;
}

int main() {

  int n;
  cin >> n;

  long long res = 0;
  // cout << divisors(n) << endl;
  for (int k = 1; k <= n; k++) {
    res += k * divisors(k);
  }
  cout << res << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll N;

int main() {
  cin >> N;

  ll ans = 0;

  rep2(i, 1, N + 1) {
    ll cnt = N / i;

    ans += i * cnt * (cnt + 1) / 2;
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll N;

int main() {
  cin >> N;

  if (N == 1) {
    cout << 1 << "\\n";
    return 0;
  }

  ll sqN = (ll)sqrt(N) + 1;
  vl table(sqN + 1, 1), prime;
  table[0] = 0;
  table[1] = 0;

  rep2(i, 2, sqN + 1) {
    if (table[i] == 0)
      continue;

    prime.push_back(i);
    ll j = 2 * i;

    while (j <= sqN) {
      table[j] = 0;
      j += i;
    }
  }

  ll len = prime.size();
  ll ans = 1;

  rep2(K, 2, N + 1) {
    ll val = K;
    ll fK = 1;

    rep(j, len) {
      if (prime[j] * prime[j] > K)
        break;

      ll cnt = 0;

      while (val % prime[j] == 0) {
        val /= prime[j];
        cnt++;
      }

      fK *= (cnt + 1);

      if (val == 1)
        break;
    }

    if (val > 1)
      fK *= 2;

    ans += K * fK;
    // cout << K << ' ' << fK << ' ' << K*fK << ' ' << ans << "\\n";
  }

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

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

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int A[1010101];
int N;

void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  ll ret = 0;
  for (i = 1; i <= N; i++) {
    for (j = i; j <= N; j += i)
      ret += j;
  }
  cout << ret << endl;
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define endl "\\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

int countDivisors(int n) {
  ll cnt = 0;
  for (ll 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;
}

int main() {
  std::ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll sum = 0;
  for (ll i = 1; i <= N; ++i) {
    sum += (i * countDivisors(i));
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl '\\n'
#define pi 2 * acos(0.0)
#define pb(a) push_back(a)
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / gcd(a, b)) * b)
#define debug(x) cerr << #x << " = " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define unsyncIO                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

using namespace std;

int main() {
  // freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
  unsyncIO;
  ll n, ans = 0;
  cin >> n;
  for (ll j = 1; j <= n; j++) {
    ll t = n / j;
    ans += t * (t + 1) / 2 * j;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
#define pi 2 * acos(0.0)
#define pb(a) push_back(a)
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / gcd(a, b)) * b)
#define debug(x) cerr << #x << " = " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define unsyncIO                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

using namespace std;

int main() {
  // freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
  unsyncIO;
  ll n, ans = 0;
  cin >> n;
  for (ll j = 1; j <= n; j++) {
    for (ll i = 1; i <= n; i++) {
      if (i % j == 0)
        ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(10000010, 0);

  rep(1, i, N + 1) {
    for (ll j = i; j <= N; j += i) {
      a.at(j)++;
    }
  }

  ll ans = 0;
  rep(1, i, N + 1) { ans += i * a.at(i); }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

void eratosthenes(vector<int> &prime) {
  rep(0, i, 10000) prime.at(i) = 1;
  prime.at(0) = prime.at(1) = 0;
  rep(0, i, 10000) {
    if (prime.at(i)) {
      for (int j = i + i; j < 10000; j += i) {
        prime.at(j) = 0;
      }
    }
  }
}

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

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

  // 素数である
  return true;
}

int main() {
  ll X;
  cin >> X;
  vector<int> prime(10000);
  eratosthenes(prime);
  vector<ll> value;
  rep(0, i, 10000) {
    if (prime.at(i) == 1) {
      value.push_back(i);
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= X; i++) {
    ll x = i;
    ll t = 1;
    for (auto v : value) {
      if (v > x) {
        break;
      }
      if (IsPrime(x)) {
        t *= 2;
        break;
      }
      ll tmp = 1;
      while (x % v == 0) {
        x /= v;
        tmp++;
      }
      t *= tmp;
    }
    ans += i * t;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  rep(i, 1, N + 1) {
    ll c = i;
    ll cnt = 1;
    while (c <= N) {
      ans += c;
      cnt++;
      c = i * cnt;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

ll N;

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

int main() {
  cin >> N;
  ll ans = 0;
  rep(i, 2, N + 1) {
    ll tmp = 1;
    auto m = prime_factor(i);
    for (auto &p : m) {
      tmp *= (p.second + 1);
    }
    tmp *= i;
    ans += tmp;
  }
  ans++;
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

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

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