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 ll = unsigned long long;
using namespace std;

ll f(ll n) { return n * (n + 1) / 2; }

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

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

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

ll f(ll n) {
  ll ans = 1;
  vector<ll> x(n + 1);
  ll num = n;

  for (ll i = 2; i <= n; i++) {
    while (num % i == 0) {
      x.at(i)++;
      num /= i;
    }
  }

  for (ll i = 2; i <= n; i++)
    ans *= x.at(i) + 1;

  return ans;
}

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
ll a[40001000];
// ll number[20],used[20];
int main() {
  ll n, i, j, sum = 0;
  cin >> n;
  sum = 0;
  ll divs[n + 1] = {0};
  // for(i=0;i<n;i++)
  // cout << divs[i] << " " ;
  // cout << endl;
  for (i = 1; i < n + 1; i++) {
    for (j = i; j < n + 1; j += i) {
      // cout << j << " ";
      divs[j]++;
      // cout << divs[j] << endl;
    }
  }
  for (i = 1; i < n + 1; i++) {
    // cout << divs[i] << " ";
    sum += i * divs[i];
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
ll a[40001000];
// ll number[20],used[20];
int main() {
  ll n, i, j, sum = 0;
  cin >> n;
  sum = 1;
  for (i = 2; i <= n; i++) {
    ll count = 1;
    // ll p = sqrt(i)+1;
    ll p = i / 2;
    // cout << p << endl;
    for (j = 2; j <= p; j++) {
      if (i % j == 0)
        count++;
    }
    // cout << i << count <<endl;
    if (i == p)
      sum += i * count;
    else
      sum += i * (count + 1);
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#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--) // 逆ループ

// 型名省略
typedef long long ll;
// 値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

// #include "./lib/generic/search.h"

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

Error: TLE

Fixed submission:

#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--) // 逆ループ

// 型名省略
typedef long long ll;
// 値
static const ll MX = 1e18;
#define NIL = -1;

using namespace std;

// #include "./lib/generic/search.h"

int main() {
  ll n, ans = 0, num = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    num = 0;
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (i / j != j) {
          num += 2;
        } else {
          num++;
        }
      }
    }
    ans += num * i;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;
  ll arr[n + 1] = {};
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      arr[j]++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += (arr[i]) * i;
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
void SieveOfEratosthenes(ll n, bool prime[], bool primesquare[], ll a[]) {
  // Create a boolean array "prime[0..n]" and
  // initialize all entries it as true. A value
  // in prime[i] will finally be false if i is
  // Not a prime, else true.
  for (ll i = 2; i <= n; i++)
    prime[i] = true;

  // Create a boolean array "primesquare[0..n*n+1]"
  // and initialize all entries it as false. A value
  // in squareprime[i] will finally be true if i is
  // square of prime, else false.
  for (ll i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

  // 1 is not a prime number
  prime[1] = false;

  for (ll p = 2; p * p <= n; p++) {
    // If prime[p] is not changed, then
    // it is a prime
    if (prime[p] == true) {
      // Update all multiples of p
      for (ll i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  ll j = 0;
  for (ll p = 2; p <= n; p++) {
    if (prime[p]) {

      primesquare[p * p] = true;
      j++;
    }
  }
}
ll countDivisors(ll n) {
  // If number is 1, then it will have only 1
  // as a factor. So, total factors will be 1.
  if (n == 1)
    return 1;

  bool prime[n + 1], primesquare[n * n + 1];

  ll a[n]; // for storing primes upto n

  // Calling SieveOfEratosthenes to store prime
  // factors of n and to store square of prime
  // factors of n
  SieveOfEratosthenes(n, prime, primesquare, a);

  // ans will contain total number of distinct
  // divisors
  ll ans = 1;

  // Loop for counting factors of n
  for (ll i = 0;; i++) {
    // a[i] is not less than cube root n
    if (a[i] * a[i] * a[i] > n)
      break;

    // Calculating power of a[i] in n.
    ll cnt = 1;           // cnt is power of prime a[i] in n.
    while (n % a[i] == 0) // if a[i] is a factor of n
    {
      n = n / a[i];
      cnt = cnt + 1; // incrementing power
    }

    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;
  unsigned long long int sum = 0;
  for (ll i = 1; i <= n; i++) {
    sum += i * countDivisors(i);
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long N;
  scanf("%ld", &N);
  long ans = 0;
  for (long j = 1; j <= N; j++) {
    long X = N / j;
    ans += (X * (X + 1) / 2) * j;
  }
  printf("%ld\\n", ans);
}


Error: TLE

Fixed submission:

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

int main() {
  long N;
  scanf("%lld", N);
  long ans = 0;
  for (long j = 1; j <= N; j++) {
    long X = N / j;
    ans += (X * (X + 1) / 2) * j;
  }
  printf("%lld", ans);
}
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;
  for (ll j = 1; j <= N; j++) {
    ll X = N / j;
    Ans += X * j * (X + 1) / 2;
  }
  cout << Ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int64_t Ans = 0;
  for (int k = 1; k <= N; k++) {
    // double kn=sqrt(k);
    int ans = 1;
    vector<int> vec(k + 1);
    int num = k; // 素因数分解する変数num

    for (int i = 2; i <= k; i++) {
      while (num % i == 0) { // 素数で割り切れなくなるまで割っていく
        vec.at(i)++;         // 割った個数を配列に足す
        num /= i;
      }
    }

    for (int i = 2; i <= k; i++) {
      ans *= vec.at(i) + 1; // それぞれを+1して掛けていく
    }
    Ans += k * ans;
  }
  cout << Ans << endl;
}
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;
// using ll = long long;
#define ll long long
int main() {
  ll N;
  cin >> N;
  // scanf("%ll", &N);
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      // if( i % j == 0)
      ans += j;
    }
  }
  // printf("%ll", ans);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (N); i++)
// using ll = long long;
int main() {
  int N;
  scanf("%d", &N);
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (i % j == 0)
        ans += i;
    }
  }
  printf("%d", ans);
  // 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
#define rep(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n + 1) {
    if (i == 0)
      continue;
    ll 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 long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 60)
#define mod 1000000007
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;
}

vector<bool> isprime(vector<bool> &prime) {
  ll N = prime.size();
  if (N >= 0)
    prime[0] = false;
  if (N >= 1)
    prime[1] = false;
  for (ll i = 2; i * i <= N; i++) {
    if (!prime[i]) {
      continue;
    }
    for (ll j = i * i; j <= N; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

ll f(ll n, vector<ll> &prime) {
  ll ret = 1, ins = n;
  for (ll i = 0; i < prime.size(); i++) {
    ll num = 0;
    while (n % prime[i] == 0) {
      num++;
      n /= prime[i];
    }

    ret *= (num + 1);
  }
  if (n != 1) {
    ret *= 2;
  }

  return ret;
}

int main() {
  ll n;
  cin >> n;
  vector<bool> prime(n + 1, true);
  vector<ll> num;
  isprime(prime);

  rep(i, n) {
    if (prime[i] == true) {
      num.push_back(i);
    }
  }

  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ans += i * f(i, num);
  }

  cout << ans << 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 (int i = 1; i <= N; i++) {
    ans += i * ((N / i) * ((N / i) + 1) / 2);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += i * num[i];
  }

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

#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
  ll t;
  t = 1;
  //    cin t;
  while (t--) {
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
      ll x = n / i;
      ans += (i + i * x) * x / 2;
    }

    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long int

ll find(int n) {
  ll ans = 1;
  int count = 0;
  while (n % 2 == 0 && n > 1) {
    n /= 2;
    count++;
  }
  ans *= (count + 1);
  for (int i = 3; i * i <= n; i += 2) {
    int count = 0;
    while (n % i == 0 && n > 1) {
      n /= i;
      count++;
    }
    ans *= (count + 1);
  }
  if (n > 1)
    ans = ans * 2;
  return ans;
}

int main() {
  ll t;
  t = 1;
  //    cin t;
  while (t--) {
    ll n;
    cin >> n;
    ll 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 rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll 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:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

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

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

int main() {
  long long N;
  cin >> N;
  vector<ll> a(N + 1);
  a[1] = 1;
  for (int k = 2; k <= N; k++) {
    ll tmp = 1;
    const auto &res = prime_factorize(k);
    for (auto p : res) {
      tmp *= (p.second + 1);
    }
    a[k] = tmp;
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
long long func(long long k) {
  long long count = 0;
  for (int i = 1; i <= k; i++) {
    if (k % i == 0)
      count++;
  }
  return count;
}
int main() {
  long long n, i, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    sum = sum + (i * (func(i)));
  }
  cout << sum;

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

// by shubham_bitsg

#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 long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<string> vs;

// #define oset tree<int, nuint_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
#define forl(i, a, b) for (int i = a; i < b; i++)
#define rfor(i, b, a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> divs(n + 1, 0);
  divs[1] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      divs[j]++;
  }
  ll sum = 0;
  forl(i, 1, n + 1) { sum += i * ((ll)divs[i] + 1); }
  cout << sum << "\\n";
}

Error: TLE

Fixed submission:

// by shubham_bitsg

#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 long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<string> vs;

// #define oset tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
#define forl(i, a, b) for (ll i = a; i < b; i++)
#define rfor(i, b, a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  map<ll, ll> divs;
  divs[1] = 0;
  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      divs[j]++;
    }
  }
  ll sum = 0;
  forl(i, 1, n + 1) { sum += i * (divs[i] + 1); }
  cout << sum << "\\n";
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using L64 = int64_t;

/* {x,y}という表現で格納される[x^y] */
vector<pair<L64, int>> prime_factorize(L64 N) {
  vector<pair<L64, int>> res;
  for (int a = 2; a * a <= N; ++a) {
    if (N % a != 0) {
      continue;
    }
    int ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

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

  L64 x = 0;
  for (int a = 1; a <= N; a++) {
    for (int n = a; n <= N; n += a) {
      x += n;
    }
  }
  cout << x;

  return 0;
}

#if 0
  vector<int> num(N + 1, 0);

  for (int i = 2; i <= N; i++) {
    vector<pair<L64, int>> res = prime_factorize(i);
    for (auto p : res) {
      num[p.first] += p.second;
    }
  }
  L64 result = 1;
  for (int i = 2; i <= N; i++) {
    result += i * num[i];
  }
  cout << result;
#endif

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using L64 = int64_t;

/* {x,y}という表現で格納される[x^y] */
vector<pair<L64, int>> prime_factorize(L64 N) {
  vector<pair<L64, int>> res;
  for (int a = 2; a * a <= N; ++a) {
    if (N % a != 0) {
      continue;
    }
    int ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main(void) {
  int N;
  L64 result = 1;
  cin >> N;
  for (int i = 2; i <= N; i++) {
    L64 n = 1;
    vector<pair<L64, int>> res = prime_factorize(i);
    for (auto p : res) {
      n *= (p.second + 1);
    }
    result += i * n;
  }
  cout << result;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#define errOut(s)                                                              \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/adaptors.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n) {
  std::vector<int64_t> sieved(n + 1, 0);
  int64_t ret = 1;
  for (int64_t p = 2; p <= n; p++) {
    for (int64_t pp = p; pp <= n; pp += p) {
      sieved[pp]++;
    }
    ret += (sieved[p] + 1) * p;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  auto const res = solve(n);
  std::cout << res << std::endl;
  return 0;
}


Error: TLE

Fixed submission:

#define errOut(s)                                                              \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/adaptors.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

template <size_t maxOfPrimes, size_t primeSize> struct PrimeTable {
  bool sieves[maxOfPrimes];
  int64_t primes[primeSize];
  size_t countOfPrimes = 0;
  constexpr PrimeTable() : sieves(), primes() {
    for (int64_t i = 0; i < maxOfPrimes; ++i) {
      sieves[i] = true;
    }
    sieves[0] = sieves[1] = false;
    for (int64_t i = 2; i < maxOfPrimes; ++i) {
      if (sieves[i]) {
        primes[countOfPrimes] = i;
        ++countOfPrimes;
        if (countOfPrimes > primeSize) {
          break;
        }
      }
      for (int64_t j = i * i; j < maxOfPrimes; j += i) {
        sieves[j] = false;
      }
    }
  }
};

const auto ps = PrimeTable<5000001, 1000000>();

int64_t f(int64_t n) {
  if (n == 1) {
    return 1;
  }

  int64_t ret = 1;
  int64_t nn = n;
  for (auto const p : ps.primes) {
    if (nn == 0) {
      break;
    }
    if (p * 2 > n) {
      break;
    }
    if (p > nn) {
      break;
    }
    int64_t count = 0;
    while (nn % p == 0) {
      count++;
      nn /= p;
    }
    ret *= (count + 1);
  }
  if (ret == 1) {
    return 2;
  }
  return ret;
  //  int64_t ret = 0;
  //  for (int64_t i = 1; i <= n; i++) {
  //    if (n % i == 0) {
  //      ret++;
  //    }
  //  }
  //  return ret;
}

int64_t solve(int64_t n) {
  int64_t ret = 0;
  for (int64_t i = 1; i <= n; i++) {
    auto const ff = f(i);
    ret += i * ff;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  auto const res = solve(n);
  std::cout << res << std::endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> ans;
  for (ll i = 2; i <= n; i++) {
    if (n % i != 0)
      continue;
    ans.emplace_back(i, 0);
    while (n % i == 0) {
      ans.back().second++;
      n /= i;
    }
  }
  if (1 != n)
    ans.emplace_back(n, 1);
  return ans;
}
int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    auto temp = factorize(i);
    ll calctemp = 1;
    for (int j = 0; j < temp.size(); j++) {
      calctemp *= temp[j].second + 1;
    }
    ans += i * calctemp;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 50;
ll a[maxn], n;
void init() {
  for (int i = 2; i <= 5 * 1e6; ++i) {
    for (int j = 2; j * i <= 1e7; ++j) {
      a[i * j]++;
    }
  }
}
int main() {

  for (int i = 2; i <= 1e7; ++i)
    a[i] = 2;
  a[1] = 1;
  init();
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; ++i)
    sum += a[i] * i;
  cout << sum << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 50;
int a[maxn];
void init() {
  for (int i = 2; i <= 5 * 1e6; ++i) {
    for (int j = 2; j <= 1e7; ++j) {
      a[i * j]++;
    }
  }
}
int main() {
  memset(a, 2, sizeof a);
  init();
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; ++i)
    sum += a[i] * i;
  cout << sum << endl;
  return 0;
}