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

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define scn(n) scanf("%d", &n)
const int N = 1e7 + 2;
using namespace std;

int main() {

  int n;
  cin >> n;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll cnt = n / i; // in how many nos i is a factor

    cnt = cnt * (cnt + 1);
    cnt /= 2;

    ans += (cnt * i);
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define scn(n) scanf("%d", &n)
const int N = 1e7 + 2;
using namespace std;
bool is_prime[N];
vector<int> prime(int n) {
  vector<int> ans;
  memset(is_prime, 1, sizeof(is_prime));

  for (int i = 2; i * i <= n; i++) {
    if (is_prime[i] == 1) {
      for (int j = i * i; j <= n; j += i)
        is_prime[j] = 0;
    }
  }

  for (int i = 2; i <= n; i++) {
    if (is_prime[i] == 1)
      ans.push_back(i);
  }
  return ans;
}

int main() {

  int n;
  cin >> n;

  vector<int> p = prime(n);
  // for(auto it:p)
  // cout<<it;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    int factor = 1;
    int num = i;
    for (auto it : p) {
      if (it > num)
        break;

      else if (num % it == 0) {
        while (num % it == 0) {
          num = num / it;
          cnt++;
        }
        factor = factor * (1 + cnt);
        cnt = 0;
      }
    }
    ans += (i * factor);
  }
  cout << ans;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL unsigned long long int
using namespace std;
#define MAXN 10000001
vector<LL> findDivisors(LL N) {
  vector<LL> div(N + 1, 0);
  for (LL i = 1; i <= N; i++) {
    for (LL j = 1; j * i <= N; j++)
      div[i * j]++;
  }
  return div;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  LL N;
  cin >> N;
  LL ans = 0;
  vector<LL> arr = findDivisors(N);
  for (LL i = 1; i <= N; i++) {
    ans += i * arr[i];
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL unsigned long long int
using namespace std;
#define MAXN 10000001
LL spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (LL i = 2; i < MAXN; i++)
    spf[i] = i;
  for (LL i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (LL i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (LL j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
vector<LL> getFactorization(int x) {
  vector<LL> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  sieve();
  LL N;
  cin >> N;
  LL ans = 0;
  for (LL i = 1; i <= N; i++) {
    vector<LL> s = getFactorization(i);
    unordered_map<LL, LL> S;
    for (auto it : s) {
      S[it] += 1;
    }
    LL p = i;
    for (auto it : S) {
      p = p * (it.second + 1);
    }
    ans += p;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

class Primes {
private:
  vector<int> Prime_Number;
  vector<bool> is_prime_;

public:
  Primes(int N) {
    is_prime_.resize(N + 1, true);
    is_prime_[0] = is_prime_[1] = false;
    for (int i = 0; i < N + 1; i++) {
      if (is_prime_[i]) {
        Prime_Number.push_back(i);
        for (int j = 2 * i; j <= N; j += i)
          is_prime_[j] = false;
      }
    }
  }
  int operator[](int i) { return Prime_Number[i]; }
  int size() { return Prime_Number.size(); }
  int back() { return Prime_Number.back(); }
  bool isPrime(int q) { return is_prime_[q]; }
};

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

class Primes {
private:
  vector<int> Prime_Number;
  vector<bool> is_prime_;

public:
  Primes(int N) {
    is_prime_.resize(N + 1, true);
    is_prime_[0] = is_prime_[1] = false;
    for (int i = 0; i < N + 1; i++) {
      if (is_prime_[i]) {
        Prime_Number.push_back(i);
        for (int j = 2 * i; j <= N; j += i)
          is_prime_[j] = false;
      }
    }
  }
  int operator[](int i) { return Prime_Number[i]; }
  int size() { return Prime_Number.size(); }
  int back() { return Prime_Number.back(); }
  bool isPrime(int q) { return is_prime_[q]; }
};

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (int num = 2; num <= n; num++) {
    ll ans = 1;
    ll c = num;
    for (int i = 2; i * i <= c; i++) {
      int cnt = 0;
      while (c % i == 0) {
        cnt++;
        c /= i;
      }
      ans *= (cnt + 1);
      if (c == 1)
        break;
    }
    if (c != 1)
      ans *= 2;
    sum += num * ans;
  }
  cout << sum + 1 << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;

#define INF (i32)1e9
#define INF_LL (i64)1e18
#define REP(i, n) for (i64 i = 0; i < n; i++)
#define RANGE(i, a, b) for (i64 i = a; i < b; i++)

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

  vector<bool> is_prime(3163);
  vector<i64> primes;
  REP(i, 3162) is_prime[i] = true;
  RANGE(i, 2, 3163) {
    if (is_prime[i]) {
      RANGE(j, i * 2, 3163) {
        if (j % i == 0)
          is_prime[j] = false;
      }
      primes.emplace_back(i);
    }
  }

  vector<i64> v(n);
  i64 ans = 1;
  v[0] = 1;
  RANGE(i, 1, n) {
    i64 po = i + 1;
    i64 p = 0;
    for (auto &&prime : primes) {
      if (prime * prime > po)
        break;
      if (po % prime == 0) {
        p = prime;
        break;
      }
    }
    v[i] = 2;
    if (p != 0) {
      i64 cnt = 1;
      while (po % p == 0) {
        po /= p;
        cnt++;
      }
      v[i] = cnt * v[po - 1];
    }
    ans += (i + 1) * v[i];
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;

#define INF (i32)1e9
#define INF_LL (i64)1e18
#define REP(i, n) for (i64 i = 0; i < n; i++)
#define RANGE(i, a, b) for (i64 i = a; i < b; i++)

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

  vector<bool> is_prime(10000);
  vector<i64> primes;
  REP(i, 10000) is_prime[i] = true;
  RANGE(i, 2, 10000) {
    if (is_prime[i]) {
      RANGE(j, i * 2, 10000) {
        if (j % i == 0)
          is_prime[j] = false;
      }
      primes.emplace_back(i);
    }
  }

  vector<i64> v(n);
  v[0] = 1;
  RANGE(i, 1, n) {
    i64 po = i + 1;
    i64 p = 0;
    for (auto &&prime : primes) {
      if (po % prime == 0) {
        p = prime;
        break;
      }
    }
    v[i] = 2;
    if (p != 0) {
      i64 cnt = 1;
      while (po % p == 0) {
        po /= p;
        cnt++;
      }
      v[i] = cnt * v[po - 1];
    }
  }

  i64 ans = 0;
  REP(i, n) ans += (i + 1) * v[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 main() {
  ll n;
  cin >> n;
  ll ans = 0, l = 0, r, cnt;
  for (ll i = 1; i <= n; i++) {
    l = i;
    r = (n / i) * i;
    cnt = (r / i) - (l / i) + 1;
    ans += (cnt * (l + r) / 2);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int mod = 1e9 + 7;

// int fac[2000007];

int mul(int a, int b) { return a * (ll)b % mod; }

// void pre() {
// 	fac[0]=1;
// 	for(ll i=1;i<2e6+5;i++) {
// 		fac[i] = mul(fac[i-1],i);
// 	}
// }

int pow(int a, int b) {
  int rs = 1;
  while (b) {
    if (b % 2)
      rs = mul(rs, a);
    a = mul(a, a);
    b /= 2;
  }
  return rs;
}

int dv(int a, int b) { return mul(a, pow(b, mod - 2)); }

// int comb(int a,int b) {
// 	return dv(fac[a], mul(fac[a-b],fac[b]));
// }

int add(int a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
  if (a < 0)
    a += mod;
  return a;
}

bool prime[10000000];
vector<ll> pr, st;

int32_t main() {
  fast unordered_map<ll, ll> mp;
  fill(prime, prime + 10000000, false);
  prime[1] = true;
  for (ll i = 2; i * i < 10000000; i++) {
    if (!prime[i]) {
      pr.push_back(i);
      mp[i * i] = 1;
      for (ll j = i * 2; j < 10000000; j += i) {
        prime[j] = true;
      }
    }
  }

  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll a = 1, k = i;
    for (auto it : pr) {
      if (it * it * it > k)
        break;
      ll cnt = 1;
      while (k % it == 0) {
        k /= it;
        cnt++;
      }
      a *= cnt;
    }
    if (!prime[k])
      a *= 2;
    else if (mp[k])
      a *= 3;
    else if (k != 1)
      a *= 4;
    // cout<<a<<" ";
    ans += (i * a);
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

long long arr[10000007];

int main() {
  long long n, sum = 0, i, j;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i) {
      arr[j]++;
    }
  }
  for (i = 1; i <= n; i++) {
    sum += (arr[i]) * i;
  }
  printf("%lld", sum);
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long int N, i, j, count = 0, d;
  long long int sum = 0;
  scanf("%lld", &N);
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= i; j++) {
      if (i % j == 0) {
        count++;
      }
    }
    d = count * i;
    sum = sum + d;
    count = 0;
  }
  printf("%lld", sum);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#define LL long long
#define LD long double
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;

long long d[10000001];

void f(long long n) {
  for (long long i = 1; i <= n; i++) {
    for (long long j = i; j <= n; j += i)
      d[j]++;
  }
}

int main() {
  FIO;
  long long n, sum = 0;
  cin >> n, f(n);
  for (long long i = 1; i <= n; i++)
    sum += i * d[i];
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, i, j, k, l, s;
  cin >> a;
  s = 0;
  for (i = 1; i <= a; i++) {
    b = 0;
    for (j = 1; j <= i; j++) {
      if (i % j == 0) {
        b++;
      }
    }
    s = s + (b * i);
  }
  cout << s << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

/*
                                                  __          __
      /\\   |   |     /\\   |  | |  |     /\\   | / |  )   /\\   |  )
     /__\\  |   |    /__\\  |--| |  |    /__\\  |<  |-<   /__\\  |-<
    /    \\ |__ |__ /    \\ |  | \\__/   /    \\ | \\ |__) /    \\ |  \\

*/

#import <bits/stdc++.h>
typedef long long ll;
#define num 10000010
#define root 10000
#define forll(i, a, b, c) for (int i = a; i <= b; i += c)
#define forll2(i, a, b, c) for (int i = a; i >= b; i -= c)
#define pb(n) push_back(n)

using namespace std;

map<int, int> m;
map<int, ll> o;

void nod() {
  forll(i, 2, root, 1) {
    forll(j, i + i, num, i) { m[j]++; }
  }
  m[1]++;
  o[1] = 1;
  forll(i, 2, num, 1) {
    m[i] += 2;
    o[i] = o[i - 1] + (i * m[i]);
  }
}

int main() {
  nod();
  int n;
  forll(i, 1, 100, 1) { cout << m[i] << " "; }
  cout << "\\n";
  while (cin >> n) {
    cout << o[n] << "\\n";
  }
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;

int main() {
  long long n;
  long long ans[10000001];
  memset(ans, 0, sizeof(ans));
  scanf("%lld", &n);
  long long nCount = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= n; j += i) {
      ans[j]++;
    }
    // printf("%lld\\n", ans);
  }
  for (long long i = 1; i <= n; i++) {
    nCount += ans[i] * i;
  }
  printf("%lld\\n", nCount);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;

int main() {
  long long n;
  long long ans[10001];
  scanf("%lld", &n);
  long long nCount = 0;
  for (long long i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i) {
      ans[j]++;
    }
    // printf("%lld\\n", ans);
  }
  for (long long i = 1; i <= n; i++) {
    nCount += ans[i] * i;
  }
  printf("%lld\\n", nCount);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long, long long>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
bool prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}
int a[10000005] = {0};
int divisor(int n) {
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  return a[n];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  divisor(n);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * a[i]);
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long, long long>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
bool prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}
int a[10000005] = {0};
int divisor(int n) {
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  return a[n];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * divisor(i));
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

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

  for (ll i = 1; i <= n; i++) {
    ll y = n / i;
    ans += y * (y + 1) * i / 2;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

bool isPrime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

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

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

  for (ll i = 1; i <= n; i++) {
    if (!isPrime(i)) {
      sum += i * divisor(i);
    } else {
      sum += i * 2;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  int n;
  cin >> n;
  vec d(n + 1);
  rep1(i, n) {
    for (int j = i; j <= n; j += i) {
      d[j]++;
    }
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  int n;
  cin >> n;
  vec f(n + 1);

  for (int j = 1; j <= n; j++) {
    f[j] = 1;
    int a = j;

    for (int i = 2; i <= sqrt(a); i++) {
      int cnt = 0;
      while (a % i == 0) {
        cnt++;
        a /= i;
      }
      f[j] *= (cnt + 1);
      if (a == 1)
        break;
    }
    if (a != 1)
      f[j] *= 2;
  }

  ll sum = 0;
  for (int k = 1; k <= n; k++) {
    sum += k * f[k];
  }

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

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

const long long N = 1e7 + 5;
vector<long long> v(N);

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

  long long ans = 0, n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; i * j <= n; j++) {
      v[i * j]++;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

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

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

  long long ans = 0, n;
  cin >> n;
  for (long long num = 1; num <= n; num++) {
    vector<long long> v;
    for (long long i = 1; i <= sqrt(num); i++) {
      if (num % i == 0) {

        if (num / i == i)
          v.emplace_back(i);
        else {
          v.emplace_back(i);
          v.emplace_back(num / i);
        }
      }
    }
    long long c = v.size();
    ans += c * num;
  }
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

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

  for (int i = 1; i <= n; ++i) {
    ULL num = n / i;
    ans += num * (num + 1) * i / 2;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

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

  long int ans = 0;

  for (int i = 1; i <= n; ++i) {
    int sub = i;
    long int f = sub;
    int p = 2;
    if (sub % p == 0) {
      int count = 0;
      while (sub % p == 0) {
        sub /= p;
        count++;
      }
      f *= (count + 1);
    }
    p++;
    while (p <= sqrt(sub)) {
      if (sub % p == 0) {
        int cou = 0;
        while (sub % p == 0) {
          sub /= p;
          cou++;
        }
        f *= (cou + 1);
      }

      p += 2;
    }
    if (sub != 1) {
      f *= 2;
    }
    // cerr << f << " " << ans << endl;
    ans += f;
  }

  cout << ans << endl;

  return 0;
}