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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define IFOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void hurui(int n, vector<bool> &nums, vector<ll> &fc) {
  nums.resize(n + 1, true);
  fc.resize(n + 1, 1);
  nums[1] = false;
  IFOR(i, 2, n) {
    if (!nums[i])
      continue;
    fc[i] = 2;
    for (int j = 2; i * j <= n; j++) {
      nums[i * j] = false;
      int tmp = i * j;
      int cnt = 0;
      while (tmp % i == 0) {
        tmp /= i;
        cnt++;
      }
      fc[i * j] *= (cnt + 1);
    }
  }
}
int main() {
  int k;
  cin >> k;

  vector<bool> nums;
  vector<ll> fc;
  hurui(k, nums, fc);
  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    ll fk = 1;
    ans += i * fc[i];
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define IFOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void hurui(int n, vector<bool> &nums, vector<map<int, int>> &fc) {
  nums.resize(n + 1, true);
  fc.resize(n + 1);
  nums[1] = false;
  IFOR(i, 2, n) {
    if (!nums[i])
      continue;
    fc[i][i] = 1;
    for (int j = 2; i * j <= n; j++) {
      nums[i * j] = false;
      int tmp = i * j;
      while (tmp % i == 0) {
        tmp /= i;
        fc[i * j][i]++;
      }
    }
  }
}
int main() {
  int k;
  cin >> k;

  vector<bool> nums;
  vector<map<int, int>> fc;
  hurui(k, nums, fc);
  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    ll fk = 1;
    for (auto t : fc[i])
      fk *= (t.second + 1);
    ans += i * fk;
  }
  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 SPEED                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
  SPEED
  int n;
  cin >> n;
  ll ans = 0;
  ll divs[n + 1] = {0};

  for (int i = 1; i <= n; i++) {
    for (int j = i; j < n + 1; j += i) {
      divs[j]++;
    }
  }

  for (int i = 1; i < n + 1; ++i) {
    ans += i * divs[i];
  }

  cout << ans;
  return 0;
}

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 ll long long
#define ld long double
void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) {
  for (int i = 2; i <= n; i++)
    prime[i] = true;

  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (prime[p]) {
      a[j] = p;
      primesquare[p * p] = true;
      j++;
    }
  }
}
int countDivisors(int n) {
  if (n == 1)
    return 1;

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

  int a[n];

  SieveOfEratosthenes(n, prime, primesquare, a);

  int ans = 1;

  for (int i = 0;; i++) {

    if (a[i] * a[i] * a[i] > n)
      break;

    int cnt = 1;
    while (n % a[i] == 0) {
      n = n / a[i];
      cnt = cnt + 1;
    }
    ans = ans * cnt;
  }

  if (prime[n])
    ans = ans * 2;

  else if (primesquare[n])
    ans = ans * 3;

  else if (n != 1)
    ans = ans * 4;

  return ans;
}
int main() {
  SPEED
  int n;
  cin >> n;

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

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

#define ll long long
#define ar array

const int mxN = 1e7;
int n, c[mxN + 1];

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

  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; j += i) // William Lin Genius
      ++c[j];
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += (ll)i * c[i];
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"

void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int 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 (int 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 (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

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

  for (int 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 (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (prime[p]) {
      // Storing primes in an array
      a[j] = p;

      // Update value in primesquare[p*p],
      // if p is prime.
      primesquare[p * p] = true;
      j++;
    }
  }
}

// Function to count divisors
int f(int 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];

  int 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
  int ans = 1;

  // Loop for counting factors of n
  for (int 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.
    int 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
    }

    // Calculating number of divisors
    // If n = a^p * b^q then total divisors of n
    // are (p+1)*(q+1)
    ans = ans * cnt;
  }

  // if a[i] is greater than cube root of n

  // First case
  if (prime[n])
    ans = ans * 2;

  // Second case
  else if (primesquare[n])
    ans = ans * 3;

  // Third casse
  else if (n != 1)
    ans = ans * 4;

  return ans; // Total divisors
}

int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  int n;
  cin >> n;
  long long int res = 0;
  for (int k = 1; k <= n; k++) {
    res += k * f(k);
  }
  cout << res << endl;

  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;

vector<long long> spf(1e7 + 1, 0);

int main() {

  long long n;
  cin >> n;

  iota(spf.begin(), spf.begin() + n + 1, 0);

  for (long long i = 2; i * i <= n; i++) {
    for (long long j = i * i; j <= n; j += i)
      spf[j] = min(spf[j], i);
  }

  long long ans = 0;

  for (long long i = 1; i <= n; i++) {
    long long x = i, cnt = 1;
    while (x != 1) {
      long long pfac = spf[x], temp = 0;
      while (x % pfac == 0)
        x /= pfac, temp++;
      cnt *= (temp + 1);
    }
    ans += (i * cnt);
  }

  cout << ans;

  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;

vector<long long> spf(1e7 + 1, 0);

int main() {

  long long n;
  cin >> n;

  iota(spf.begin(), spf.begin() + n, 0);

  for (long long i = 2; i * i <= n; i++) {
    for (long long j = i * i; j <= n; j += i)
      spf[j] = min(spf[j], i);
  }

  long long ans = 0;

  for (long long i = 1; i <= n; i++) {
    long long x = i, cnt = 1;
    while (x != 1) {
      long long pfac = spf[x], temp = 0;
      while (x % pfac == 0)
        x /= pfac, temp++;
      cnt *= (temp + 1);
    }
    ans += (i * cnt);
  }

  cout << ans;

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

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

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 0;
  for (int mul = 1; mul <= n; mul++) {
    int k = n / mul;
    ans += (ll)k * mul * (1 + k) / 2;
  }

  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int mod = 1000000007;
ll solve(int n) {
  ll ans = 0;
  int i = 1;
  for (i = 1; i * i < n; i++) {
    if (n % i == 0) {
      ans = ans + 2;
    }
  }
  if (i * i == n) {
    ans++;
  }
  return ans;
}

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, sum = 1;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    sum = sum + i * solve(i);
  }

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

#if __has_include("debug.h")
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a * b) / gcd(a, b))

void solve();

const int N = 1e7 + 1;

vector<int> divisor(N);

void init() {
  int i, j;
  for (i = 1; i <= N; i++) {
    for (j = i; j <= N; j += i) {
      divisor[j]++;
    }
  }
}

int32_t main() {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast

      int t = 1;
  // cin>>t;

  while (t--)
    solve();
  return 0;
}

void solve() {
  int i, j;
  int n;
  cin >> n;

  init();

  int sum = 0;

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

  cout << sum << endl;
}

Error: TLE

Fixed submission:

#if __has_include("debug.h")
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a * b) / gcd(a, b))

void solve();

int cof(int n) {
  int cnt = 0;

  // stack<int> st;
  // vector<int> v;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i) {
        // v.push_back(i);
        cnt++;
      } else {
        // v.push_back(i);
        // st.push(n/i);
        cnt += 2;
      }
    }
  }

  // while(!st.empty())
  // {
  // 	v.push_back(st.top());
  // 	st.pop();
  // }
  return cnt;
}

int32_t main() {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast

      int t = 1;
  // cin>>t;

  while (t--)
    solve();
  return 0;
}

void solve() {
  int i, j;
  int n;
  cin >> n;

  int sum = 0;

  for (i = 1; i <= n; i++) {
    sum += i * cof(i);
  }

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

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

#define ll long long
#define ar array

const int mxN = 1e7;
int n, c[mxN + 1];

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

  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= n; j += i)
      ++c[j];

  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += (ll)i * c[i];
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int f(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else {
        cnt += 2;
      }
    }
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  unsigned long long suma = 0;
  for (int i = 1; i <= n; i++)
    suma += (unsigned long long)i * f(i);

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

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

const int M = 10000001;
ll a[M];
int main() {
  int N;
  cin >> N;
  fill(a, a + M, 1);
  for (ll i = 2; i < M; i++) {
    for (ll j = 1; i * j < M; j++) {
      a[i * j]++;
    }
  }
  ll ans = 0;
  /*for (ll i = 1; i <= N; i++) {
      ans += i * a[i];
  }*/
  for (long long i = 1; i <= N; i++) {
    ans += i * a[i];
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

long long int divisor(long long n) {
  // vector<long long> ret;
  int count = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      // ret.push_back(i);
      count++;
      if (i * i != n) {
        // ret.push_back(n / i);
        count++;
      }
    }
  }
  // sort(ret.begin(), ret.end()); // 昇順に並べる
  return count;
}

int main(void) {
  long long int N;
  cin >> N;
  unsigned long long int ans = 0;
  // long long int num = 0;
  int temp = 0;
  for (int i = 1; i <= N; i++) {
    temp = divisor(i);
    ans += i * temp;
  }
  // unsigned long long int ans = num * temp;

  cout << ans << endl;

  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

// https://atcoder.jp/contests/abc172/tasks/abc172_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 二乗法によるべき乗
int ipow(int base, int exp) {
  int result = 1;
  while (exp) {
    if (exp & 1)
      result *= base;
    exp >>= 1;
    base *= base;
  }

  return result;
}

// 等比数列の和(a=初項、r=公比、項数=n)
int sumOfTouhi(int a, int r, int n) { return a * ipow(r, n) - a / (r - 1); }

// 等差数列の和(a=初項、d=公差、項数=n)
int sumOfTousa(int a, int d, int n) { return n * (2 * a + (n - 1) * d) / 2; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  // １の倍数＋２の倍数＋３の倍数＋・・・
  int ans = 0;
  FOR(i, 1, N + 1) { ans += sumOfTousa(i, i, N / i); }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

// https://atcoder.jp/contests/abc172/tasks/abc172_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 約数の個数
template <int_fast64_t max_N> struct Prime {
  int cnt[max_N] = {0};
  constexpr Prime() : cnt() {
    for (int_fast64_t i = 1; i < max_N; ++i) {
      for (int_fast64_t j = i; j < max_N; j += i)
        cnt[j]++;
    }
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  // １の倍数＋２の倍数＋３の倍数＋・・・
  constexpr auto d = Prime<65535>();
  int ans = 0;
  FOR(i, 1, N + 1) { ans += d.cnt[i] * i; }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// https://atcoder.jp/contests/abc172/tasks/abc172_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> d(N + 1);
  // １の倍数＋２の倍数＋３の倍数＋・・・
  FOR(i, 1, N + 1) {
    for (int j = i; j <= N; j += i)
      d[j]++;
  }
  int ans = 0;
  FOR(i, 1, N + 1) { ans += d[i] * i; }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

// https://atcoder.jp/contests/abc172/tasks/abc172_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

const int SZ = 10000001;
// const int SZ = 101;
// 約数列挙
vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ALL(ret));
  return ret;
}

// エラトステネスの篩
vector<int> Eratosthenes(const int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  auto v = Eratosthenes(N);
  int ans = 0;
  bitset<SZ> bt;
  for (int i = N; i >= 1; i--) {
    // 計算済みならスキップ
    if (bt[i])
      continue;
    // 素数の場合
    if (find(ALL(v), i) != v.end()) {
      ans += i * (i == 1 ? 1 : 2);
    } else {
      vector<int> t = divisor(i);
      ans += i * t.size();
    }
  }
  cout << ans << 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 int ans = 0;

  vector<long long int> dp(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      dp[j]++;
    ans += i * dp[i];
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// const int N = 1e2+5;
int N = 1e7 + 5;
vector<bool> p(N, true);
vector<int> prime, divisor(N, 2);

void seive() {
  p[0] = p[1] = false;

  for (int i = 2; i * i < N; i++)
    if (p[i])
      for (int j = i * i; j < N; j += i)
        p[j] = false;

  for (int i = 0; i < N; i++)
    if (p[i])
      prime.push_back(i);
}

int solve(int x) {
  int ans = 1;
  for (int i = 0; prime[i] <= x; i++) {
    int d = 0;
    while (x % prime[i] == 0) {
      x = x / prime[i];
      d++;
    }
    ans *= (d + 1);
  }
  return ans;
}

void save() {
  // cout << "save()" << endl;
  divisor[1] = 1;
  for (int i = 2; i < N; i++)
    if (!p[i]) {
      divisor[i] = solve(i);
      // cout << i << " :: " << divisor[i]<< endl;
    }
}

int main() {
  // freopen("input.txt" , "r" , stdin);
  // freopen("ouput.txt" , "w" , stdout);
  int n;
  cin >> n;
  N = n + 2;
  seive();
  save();

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    // cout << i << " : " << divisor[i] << endl;
    ans += i * divisor[i];
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long int> dp(n + 1, 0);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      dp[j]++;
  long long int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += i * dp[i];

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// const int N = 1e2+5;
const int N = 1e7 + 5;
vector<bool> p(N, true);
vector<int> prime, divisor(N, 2);

void seive() {
  p[0] = p[1] = false;

  for (int i = 2; i * i < N; i++)
    if (p[i])
      for (int j = i * i; j < N; j += i)
        p[j] = false;

  for (int i = 0; i < N; i++)
    if (p[i])
      prime.push_back(i);
}

int solve(int x) {
  int ans = 1;
  for (int i = 0; prime[i] <= x; i++) {
    int d = 0;
    while (x % prime[i] == 0) {
      x = x / prime[i];
      d++;
    }
    ans *= (d + 1);
  }
  return ans;
}

void save() {
  // cout << "save()" << endl;
  divisor[1] = 1;
  for (int i = 2; i < N; i++)
    if (!p[i]) {
      divisor[i] = solve(i);
      // cout << i << " :: " << divisor[i]<< endl;
    }
}

int main() {
  // freopen("input.txt" , "r" , stdin);
  // freopen("ouput.txt" , "w" , stdout);
  seive();
  save();
  int n;
  cin >> n;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    // cout << i << " : " << divisor[i] << endl;
    ans += i * divisor[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;
using ll = long long;
using P = pair<int, int>;

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

  vector<int> F(N + 1, 0);
  for (ll i = 1; i <= N; i++) {
    ll j = 1;
    while (i * j <= N) {
      F.at(i * j)++;
      j++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += i * F.at(i);
  }

  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;
using ll = long long;
using P = pair<int, int>;

vector<ll> F(10000000, 0);

ll prime_count(ll N, ll n, ll now) {
  if (F.at(n) > 0) {
    F.at(N) = F.at(n) * now;
  }
  for (ll a = 2; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    ll ex = 0;
    while (n % a == 0) {
      ex++;
      n /= a;
    }
    return prime_count(N, n, now * (ex + 1));
  }
  if (n != 1) {
    F.at(N) = now * 2;
    return now * 2;
  }
  F.at(N) = now;
  return now;
}

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

  ll ans = 0;
  for (ll K = 1; K <= N; K++) {
    ll fk = prime_count(K, K, 1);
    ans += K * fk;
  }
  cout << ans << endl;
}