alexjercan/bugnet huggingface dataset:
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;

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

  ll t = 1;
  // cin>>t;

  while (t--) {
    ll n, m, k;
    cin >> n >> m >> k;

    vector<ll> a(n), b(m);
    ll left = k;
    for (ll i = 0; i < n; ++i)
      cin >> a[i];
    for (ll i = 0; i < m; ++i) {
      cin >> b[i];
      if (i != 0) {
        b[i] += b[i - 1];
      }
    }

    ll i = 0;
    for (; i < n; ++i) {
      if (left >= a[i]) {
        left -= a[i];
      } else
        break;
    }
    --i;

    ll ans = i + 1;
    while (1) {
      ll x = upper_bound(b.begin(), b.end(), left) - b.begin();
      ans = max(ans, i + 1 + x);
      if (i >= 0) {
        left += a[i];
        --i;
      }

      if (i == -1) {
        x = upper_bound(b.begin(), b.end(), left) - b.begin();
        ans = max(ans, i + 1 + x);
        break;
      }
    }

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

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;

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

  ll t = 1;
  // cin>>t;

  while (t--) {
    ll n, m, k;
    cin >> n >> m >> k;

    vector<ll> a(n), b(m);
    for (ll i = 0; i < n; ++i)
      cin >> a[i];
    for (ll i = 0; i < m; ++i)
      cin >> b[i];

    ll i = 0, j = 0, ans = 0;
    while (i < n and j < n and k > 0) {
      if (a[i] <= b[j] and a[i] <= k) {
        ++ans;
        k -= a[i];
        ++i;
      } else if (a[i] > b[j] and b[j] <= k) {
        ++ans;
        k -= b[j];
        ++j;
      }

      if (a[i] > k and b[j] > k)
        break;
    }

    if (j == n) {
      while (a[i] <= k) {
        ++ans;
        k -= a[i];
        ++i;
      }
    }

    if (i == n) {
      while (b[j] <= k) {
        ++ans;
        k -= b[j];
        ++j;
      }
    }

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

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

#include <bits/stdc++.h>
using namespace std;
// #define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\\n'
#define forn(i, a, b) for (ll i = a; i <= b; i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// cout << fixed << setprecision(12) <<x<<endl;
const int MAX = 1e7;
ll a[MAX], b[MAX];
int main() {
  fastIO;
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif

  int n;
  cin >> n;
  ll ans = 0;
  forn(i, 1, n) {
    ll div = n / i;
    ll s = (div * (div + 1)) / 2;
    ans += s * i;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\\n'
#define forn(i, a, b) for (ll i = a; i <= b; i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// cout << fixed << setprecision(12) <<x<<endl;
const int MAX = 1e7;
ll a[MAX], b[MAX];
int main() {
  fastIO;
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif

  map<ll, ll> m;
  ll n;
  cin >> n;
  forn(i, 1, n) {
    ll c = 0;
    forn(j, 1, n) {
      if (i % j == 0)
        c++;
    }
    m[i] = c;
  }
  ll sum = 0;

  for (auto &x : m) {
    sum += (x.ft * x.sd);
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  vector<ll> v(10000000, 0);
  v[1] = 1;
  for (ll i = 1; i <= 10000000; i++) {
    ll j = 1;
    while (i * j <= 10000000) {
      v[i * j] = v[i * j] + 1;
      j++;
    }
  }
  ll n, count = -1;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    count += i * v[i];
  }
  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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 count(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() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * count(i));
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// GNU C Compiler
// template<class T> inline string toString(T x) { ostringstream sout; sout <<
// x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
// using pair<T1, T2> = p12;

// container
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ALL(v) v.begin(), v.end()

// repetition
#define REP(n) for (int i = 0; i < (n); i++)
#define REPj(n) for (int j = 0; j < (n); j++)
#define REPinit(i, a, n) for (ull i = (a); i < (n); i++)
#define REPinitj(j, a, n) for (ull j = (a); j < (n); j++)

// algorithm
// #define SORT(c) sort((c).begin(),(c).end())

// constant

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// Optimizer
//  #pragma GCC optimize("Ofast")
//  #pragma GCC
//  target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ull N;
  cin >> N;

  ull ans = 0;
  ull y;
  REPinit(i, 1, N + 1) {
    y = int(N / i);
    ans += ((y * (y + 1) * i) / 2);
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

// GNU C Compiler
// template<class T> inline string toString(T x) { ostringstream sout; sout <<
// x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
// using pair<T1, T2> = p12;

// container
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ALL(v) v.begin(), v.end()

// repetition
#define REP(n) for (int i = 0; i < (n); i++)
#define REPj(n) for (int j = 0; j < (n); j++)
#define REPinit(i, a, n) for (int i = (a); i < (n); i++)
#define REPinitj(j, a, n) for (int j = (a); j < (n); j++)

// algorithm
// #define SORT(c) sort((c).begin(),(c).end())

// constant

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// Optimizer
//  #pragma GCC optimize("Ofast")
//  #pragma GCC
//  target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/

ull divmap[10000005];

vector<pair<ull, ull>> prime_factorize(ull N) {
  vector<pair<ull, ull>> res;
  for (ull a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    ull ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ull N;
  cin >> N;

  vector<pair<ull, ull>> tmp;
  ull ans = 0;
  ull divNum = 0;
  REPinit(i, 2, N + 1) {
    divNum = 1;
    tmp = prime_factorize(i);
    for (auto p : tmp) {
      divNum *= (p.second + 1);
    }
    ans += (i * divNum);
  }

  cout << (ans + 1) << endl;

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

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

using ll = long long;

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

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += i;
    for (ll j = i + i; j <= N; j += i) {
      ans += j;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

using ll = long long;

template <typename T> map<T, int> primeFactorize(T n) {
  map<T, int> ret;
  for (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() {
  int N;
  cin >> N;

  ll ans = 1;
  for (ll i = 2; i <= N; i++) {
    ll val = 1;
    for (auto pf : primeFactorize(i)) {
      val *= (pf.second + 1);
    }
    ans += i * val;
  }

  cout << ans << endl;

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

#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {

  long long int i, N;
  long long int ans = 0;
  cin >> N;

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

    long long int x = N / i;
    ans += i * x * (x + 1) / 2;
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int fun(int N, int p) {

  if (N == 1)
    return p;

  int i = 2;

  while (i * i <= N) {

    if (N % i == 0)
      break;

    i++;
  }

  if (i * i > N)
    return (p * 2);

  int count = 0;

  while (N % i == 0) {

    N /= i;
    count++;
  }

  return fun(N, p * (count + 1));
}

int main() {

  int i, N;
  long long int ans = 0;
  cin >> N;

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

    ans += i * fun(i, 1);
  }

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

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

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

int N;

ll cal(ll x) {
  ll lst = N / x;
  return (1 + lst) * lst / 2;
}

void solve() {
  ll ans = 0;
  for (ll d = 1; d <= N; ++d) {
    ans += d * cal(d);
  }
  cout << ans << '\\n';
}

int main() {
  cin >> N;
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

int N;

ll div(ll x) {
  ll ans = 0;
  for (ll i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      ans++;
      if (x / i != i)
        ans++;
    }
  }
  return ans;
}

void solve() {
  ll ans = 0;
  for (ll i = 1; i <= N; ++i)
    ans += i * div(i);
  cout << ans << '\\n';
}

int main() {
  cin >> N;
  solve();
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll c2(ll x) { return x * (x - 1) / 2; }
void solve() {
  int n;
  scanf("%d", &n);
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    int cou = n / i;
    ans += i * c2(cou + 1);
  }
  printf("%lld\\n", ans);
}
int main() { solve(); }


Error: TLE

Fixed submission:

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

int SieveNbOfDiv(int NumberOfDivisors[], int IndexCount[], int Limit) {
  for (int i = 1; i * i <= Limit; i++) {
    NumberOfDivisors[i * i] += 1;
    for (int j = i * (i + 1); j <= Limit; j += i)
      NumberOfDivisors[j] += 2;
  }
  int Count = 0;
  for (int i = 1; i <= Limit; i++) {
    Count += NumberOfDivisors[i];
    NumberOfDivisors[i] = Count;
    IndexCount[i] = Count;
  }
  return Count;
}

void SieveDivisors(int IndexCount[], int NumberOfDivisors[], int Divisors[],
                   int Limit) {
  for (int i = 1; i <= Limit; i++) {
    Divisors[IndexCount[i - 1]++] = 1;
    Divisors[IndexCount[i] - 1] = i;
  }
  for (int i = 2; i * i <= Limit; i++) {
    Divisors[IndexCount[i * i - 1]++] = i;
    for (int j = i * (i + 1); j <= Limit; j += i) {
      Divisors[IndexCount[j - 1]++] = i;
      Divisors[NumberOfDivisors[j - 1] + NumberOfDivisors[j] -
               IndexCount[j - 1]] = j / i;
    }
  }
}

int main() {

  int N;
  cin >> N;

  int *NumberOfDivisors = (int *)calloc(N + 1, sizeof(int));
  int *IndexCount = (int *)calloc(N + 1, sizeof(int));
  int size = SieveNbOfDiv(NumberOfDivisors, IndexCount, N);

  int *Divisors = (int *)calloc(size + 1, sizeof(int));
  SieveDivisors(IndexCount, NumberOfDivisors, Divisors, N);

  ll sum = 0;

  for (int i = 1; i <= N; i++) {
    sum += i * (NumberOfDivisors[i] - NumberOfDivisors[i - 1]);
  }
  cout << sum;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 7;
int isp[maxn];
ll ex(int x) {
  ll ans = 1;
  for (int i = 2; i * i <= x; i++) {
    int cnt = 0;
    while (x % i == 0) {
      x /= i;
      cnt++;
    }
    ans *= (cnt + 1);
    if (x == 1)
      break;
  }
  if (x != 1)
    ans *= 2;
  return ans;
}
void init(ll n) {
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j * i <= n; j++) {
      isp[i * j]++;
    }
  }
}
int main() {

  ll n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    isp[i] = 1;
  init(n);
  // for(int i=2;i<=n;i++) isp[i]=ex(i);
  for (ll i = 1; i <= n; i++) {
    ans += i * isp[i];
    //  printf ("%lld %d\\n",i,isp[i]);
  }
  printf("%lld\\n", ans);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 7;
int isp[maxn];
ll ex(int x) {
  ll ans = 1;
  for (int i = 2; i * i <= x; i++) {
    int cnt = 0;
    while (x % i == 0) {
      x /= i;
      cnt++;
    }
    ans *= (cnt + 1);
    if (x == 1)
      break;
  }
  if (x != 1)
    ans *= 2;
  return ans;
}
int main() {

  ll n, ans = 0;
  cin >> n;
  isp[1] = 1;
  for (int i = 2; i <= n; i++)
    isp[i] = ex(i);
  for (ll i = 1; i <= n; i++) {
    ans += i * isp[i];
    // printf ("%d %d\\n",i,isp[i]);
  }
  printf("%lld\\n", ans);
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long ll;

int main() {
  int64_t N;
  cin >> N;
  int64_t 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 <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long ll;

int main() {

  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      ans += j;
    }
  }

  p(ans);

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

#include <algorithm>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
/*

*/
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  REPD(i, 1, n + 1) { ans += (ll)i * (n / i) * (n / i + 1) / 2; }
  fin(ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
/*

*/
bool is_prime(long long N) {
  if (N == 1)
    return false;
  for (long long i = 2; i * i <= N; ++i) {
    if (N % i == 0)
      return false;
  }
  return true;
}

// Nまでの素数れっきょ
vector<ll> primes(ll N) {
  vector<ll> res;
  res.push_back(2);
  for (ll i = 3; i <= N; i += 2) {
    if (is_prime(i)) {
      // cout << i << "の素数判定" << endl;
      res.push_back(i);
    }
  }
  return res;
}

map<long long, int> primeMap(ll N, vector<ll> primes) {
  map<long long, int> z;
  // cout << "primesize = " << primes.size() << endl;
  for (ll i = 0; i < primes.size(); i++) {
    // cout << "i = "<<  i << endl;
    while (N % primes[i] == 0) {
      z[primes[i]]++;
      N /= primes[i];
    }
  }
  if (N != 1)
    z[N]++;
  return z;
}

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  ll tempans;
  vector<ll> primed = primes(n);
  REPD(i, 1, n + 1) {
    tempans = 1;
    map<ll, int> primes = primeMap(i, primed);
    for (const auto &p : primes) {
      // cout << p.first << " " << p.second << endl;
      tempans *= p.second + 1;
    }
    ans += tempans * i;
  }
  fin(ans);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<int, int>
#define ppll pair<pll, pll>
#define mod 1000000007
unsigned int bp(int n) // built_in_pop_count //
{
  unsigned int count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;

      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int32_t main() {
  SPEED;
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += (i * (n / i) * (1 + n / i)) / 2;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<int, int>
#define ppll pair<pll, pll>
#define mod 1000000007
unsigned int bp(int n) // built_in_pop_count //
{
  unsigned int count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;

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

#include <bits/stdc++.h>

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long ll;
int sieve[10000001];
void getsieve(int n) {
  for (int i = 0; i <= n; i++) {
    sieve[i] = i;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (sieve[i] == i) {
      for (ll j = i * i; j <= n; j += i) {
        if (sieve[j] == j) {
          sieve[j] = i;
        }
      }
    }
  }
}
ll div(ll n) {
  map<int, int> mp;
  while (n > 1) {
    mp[sieve[n]]++;
    n /= sieve[n];
  }
  ll res = 1;
  for (auto it : mp) {
    res *= (it.second + 1);
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
// online submission
#endif
  int n;
  cin >> n;
  getsieve(n);
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    res += div(i) * i;
  }
  cout << res;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
typedef long long ll;
ll div(ll n) {
  ll res = 1;
  for (int i = 2; (ll)i * i <= n; i++) {
    if (n % i == 0) {
      int count = 0;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      res *= (count + 1);
    }
  }
  if (n > 1) {
    res *= 2;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
// online submission
#endif
  int n;
  cin >> n;
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    res += div(i) * i;
  }
  cout << res;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// time out
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
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;
}

Error: TLE

Fixed submission:

// time out
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll ans = 0;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= i; j++) {
      if (i % j == 0)
        ans += i;
    }
  }

  cout << ans << endl;
}