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

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll Max = 10000000;
ll divs[Max + 66];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i <= Max; i++) {
    for (int j = i; j <= Max; j += i) {
      divs[j] += 1;
    }
  }
  ll n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    ans += (divs[i] * i);
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int Max = 4000;
int t[Max + 5];
vector<int> a;

void ciur() {
  t[0] = 1;
  t[1] = 1;
  int i = 4;
  while (i <= Max) {
    t[i] = 1;
    i += 2;
  }
  i = 3;
  while (i * i <= Max) {
    if (t[i] == 0) {
      int k = i * i;
      while (k <= Max) {
        t[k] = 1;
        k += i;
      }
    }
    i += 2;
  }
  for (int j = 2; j <= Max; j++) {
    if (t[j] == 0)
      a.push_back(j);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ciur();
  ll n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ll x = i;
    ll len = -1, f = 0, p = 0, nrdiv = 1;
    while (f * f <= x) {
      len++;
      f = a[len];
      p = 0;
      while (x % f == 0) {
        x /= f;
        p++;
      }
      if (p > 0)
        nrdiv *= (p + 1);
      if (len == a.size() - 1)
        break;
    }
    if (x > 1)
      nrdiv *= 2;
    ans += nrdiv * i;
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll, ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(), v.end())
#define ull unsigned long long
#define tell(a) cout << a << " "
#define el cout << endl
#define rev(v) reverse(v.begin(), v.end())
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ld long double
#define mem(a, b) memset(a, b, sizeof(a))
#define M 1000000007

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

ll a[10000001];
int main() {
  IOS;
  int n;
  cin >> n;
  for (int i = 2; i <= 10000000; i++)
    a[i] = 2;
  a[1] = a[0] = 1;
  for (int i = 2; i * i <= n; i++) {
    for (int j = i * i; j <= n; j += i) {
      if (j == i * i)
        a[j]++;
      else
        a[j] += 2;
    }
  }
  for (int i = 2; i <= n; i++) {
    a[i] = a[i] * i;
    a[i] += a[i - 1];
  }
  cout << a[n] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll, ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(), v.end())
#define ull unsigned long long
#define tell(a) cout << a << " "
#define el cout << endl
#define rev(v) reverse(v.begin(), v.end())
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ld long double
#define mem(a, b) memset(a, b, sizeof(a))
#define M 1000000007

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

int main() {
  IOS;
  int n;
  cin >> n;
  ll a[n + 2];
  rep(i, 0, n + 1) {
    a[i] = i;
    if (i % 2 == 0)
      a[i] = 2;
  }
  for (int i = 3; i * i <= n; i += 2) {
    if (a[i] == i) {
      for (int j = i * i; j <= n; j += i) {
        if (a[j] == j)
          a[j] = i;
      }
    }
  }
  ll b[n + 2];
  b[1] = 1;
  for (int i = 2; i <= n; i++) {
    ll x = i;
    unordered_map<int, int> m;
    while (x != 1) {
      m[a[x]]++;
      x /= a[x];
    }
    ll ans = 1;
    for (auto it = m.begin(); it != m.end(); it++)
      ans = ans * (it->second + 1);
    b[i] = b[i - 1] + ans * i;
  }
  cout << b[n] << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
long long sum = 0LL;

int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long t = (long long)n / i;
    t = ((1 + t) * t / 2 * i);
    sum += t;
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int n, k;
int sum = 0;

// long long mem[1000006];
int f(int t) {
  //	if(mem[t] != -1LL) return mem[t];

  int tot = 0;
  for (int i = 1; i <= t; i++)
    if (t % i == 0)
      tot++;

  //	mem[t] = tot;
  //	if(n % t == 0) mem[n / t] = mem[n] / mem[t];

  return tot;
}

int main() {
  //	memset(mem, -1, sizeof(mem));
  cin >> n;
  f(n);
  for (k = 1; k <= n; k++)
    sum += (k * f(k));
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> f(n + 1);

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

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> f(n + 1);

  for (int i = 1; i <= n; i++)
    f[i] = 1;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i / 2; j++) {
      if (i % j == 0)
        f[i]++;
    }
  }

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

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;

int check[10000007];

vector<long long int> p;

int v[10000007];

long long int calc(long long int K) {

  long long int num = 1;

  long long int tmp = K;

  for (int i = 0;; i++) {
    if (p[i] * p[i] > K) {
      break;
    }
    long long int cnt = 0;
    while ((tmp % p[i]) == 0) {
      tmp /= p[i];
      cnt++;
    }

    num *= (cnt + 1);
  }

  if (tmp > 1) {
    num *= 2;
  }
  return num;
}

long long int F[10000007];
long long int INF = 10000000;

int main(void) {

  cin >> N;

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

  for (int i = 2; i <= 10000000; i++) {
    if (check[i] == 0) {
      p.push_back(i);
    }
  }

  F[1] = 1;

  for (int i = 0; i < (int)p.size(); i++) {
    long long int tmp = 1;
    int cnt = 1;
    while (1) {
      tmp *= p[i];
      if (tmp > INF) {
        break;
      }
      cnt++;
      F[tmp] = cnt;
      // cout << tmp << endl;
    }
  }

  for (int i = 1; i <= INF; i++) {
    if (F[i] > 0) {
      continue;
    }
    int y;
    for (int j = 0; j < (int)p.size(); j++) {
      if (i % p[j] == 0) {
        y = (int)p[j];
        break;
      }
    }

    int cnt = 1;

    int tmp = i;
    while (tmp % y == 0) {
      tmp /= y;
      cnt++;
    }

    F[i] = F[tmp] * cnt;
  }

  long long int ans = 0;

  for (long long int k = 1; k <= (long long int)N; k++) {

    ans += k * F[k];
  }

  /*	for (int i = 1; i <= 20; i++) {
                  cout << "F[" << i << "]= " << F[i] << endl;
          }*/

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;

int check[10000007];

vector<long long int> p;

long long int calc(long long int K) {

  long long int num = 1;

  long long int tmp = K;

  for (int i = 0;; i++) {
    if (p[i] * p[i] > K) {
      break;
    }
    long long int cnt = 0;
    while ((tmp % p[i]) == 0) {
      tmp /= p[i];
      cnt++;
    }

    num *= (cnt + 1);
  }

  if (tmp > 1) {
    num *= 2;
  }
  return num;
}

int main(void) {

  cin >> N;

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

  for (int i = 2; i <= 10000000; i++) {
    if (check[i] == 0) {
      p.push_back(i);
    }
  }

  long long int ans = 0;

  for (long long int k = 1; k <= (long long int)N; k++) {

    ans += k * calc(k);
  }

  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
#define endl '\\n'
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define mm memset
#define PI 3.14159265358979323846264338327950288419716939937510
#define MAXI (ll)2e5 + 3
#define M 998244353
ll power(ll a, ll b) {

  ll ans = 1;
  while (b--) {
    ans = ans * a;
  }
  return ans;
}
void solve() {

  ll i = 0;
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll str = i;
    ll no_of_terms = n / i;
    ll common = i;
    ll res = no_of_terms * (2 * i + (no_of_terms - 1) * i) / 2;
    //   cout<<res<<" ";
    ans += res;
  }
  cout << ans << endl;
}
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  for (ll i = 0; i < t; i++) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\\n'
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define mm memset
#define PI 3.14159265358979323846264338327950288419716939937510
#define MAXI (ll)2e5 + 3
#define M 998244353
void solve() {

  ll i = 0;
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (i / j != j)
          ans += i;
        ans += i;
      }
    }
  }
  cout << ans << endl;
}
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  for (ll i = 0; i < t; i++) {
    solve();
  }
  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)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  vector<int> S(N + 1);
  int now = 2;
  while (now * now <= N) {
    S[now * now]++;
    for (int i = now * now + now; i <= N; i += now) {
      S[i] += 2;
    }
    now++;
  }

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll s = S[i] + 2;
    if (i == 1)
      s--;
    ans += s * i;
    // cout << i << " " << ans << endl;
  }

  cout << ans << endl;

  return 0;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  map<int, int> S;
  int now = 2;
  while (now * now <= N) {
    S[now * now]++;
    for (int i = now * now + now; i <= N; i += now) {
      S[i] += 2;
    }
    now++;
  }

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll s = S[i] + 2;
    if (i == 1)
      s--;
    ans += s * i;
    // cout << i << " " << ans << endl;
  }

  cout << ans << 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 < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

  ll ans = 0;
  int l = 1;
  while (l <= n) {
    ans += Gauss(n / l) * l;
    l++;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

ll n;
ll calc_prime_Factor(ll n) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= n; a++) { // nの平方根まで調べる
    if (n % a != 0)
      continue;
    ll ex = 0; // 指数

    // 割れる限り割り続ける
    while (n % a == 0) {
      ex++;
      n /= a;
    }
    // その結果を push
    res.push_back({a, ex});
  }
  // 最後に残った数について
  if (n != 1)
    res.push_back({n, 1});

  ll ans = 1;
  for (int i = 0; i < res.size(); i++) {
    ans *= (res[i].second + 1);
  }

  return ans;
}

int main() {
  cin >> n;
  ll calc_ans = 0;
  for (int i = 1; i <= n; i++) {
    ll total_prime_Factor = 0;
    total_prime_Factor = calc_prime_Factor(i);
    calc_ans += i * total_prime_Factor;
  }

  cout << calc_ans << endl;

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

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    int cnt = n / i;
    long long int res = (long long)cnt * (cnt + 1) / 2 * i;
    ans += res;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

vector<int> v;
unsigned long long int Divisors(unsigned long long int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal,
      // count only one
      if (n / i == i)
        cnt++;
      else // Otherwise count both
        cnt = cnt + 2;
    }
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int n, sum = 1;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    sum += Divisors(i) * i;
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
  // Xの約数列挙はO(X^(1/2))だがこれでは全く間に合わない
  // 1~Nの倍数をひたすら列挙する方針に変更
  ll N;
  cin >> N;
  ll ans = 0;
  rep2(i, 1, N + 1) {
    ll tmp = N / i;
    ans += i * (tmp + 1) * tmp / 2;
  }
  cout << ans << endl;
}

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// 素数列挙
vector<ll> prime_list(ll n) {
  vector<bool> is_prime(n + 1, true);
  vector<ll> res;
  int i = 2;
  while (pow(i, 2) <= n) {
    if (is_prime[i]) {
      ll j = i + i;
      while (j <= n) {
        is_prime[j] = false;
        j += i;
      }
    }
    i++;
  }
  for (ll i = 0; i <= n; ++i) {
    if (is_prime[i] && i >= 2) {
      res.push_back(i);
    }
  }
  return res;
}

map<ll, map<ll, ll>> cache;
vector<ll> cache_prime = prime_list(10000);

// 素因数分解
map<ll, ll> prime_factorize(ll N) {
  map<ll, ll> res;

  for (auto i : cache_prime) {
    if (i * i > N) {
      break;
    }
    while (N % i == 0) {
      res[i]++;
      N /= i;

      // 小さくなったらcacheを探す
      if (cache.find(N) != cache.end()) {
        for (auto a : cache[N]) {
          if (res.find(a.first) != res.end()) {
            res[a.first] += a.second;
          } else {
            res[a.first] = a.second;
          }
        }
        N = 1;
        break;
      }
    }
  }
  if (N != 1) {
    res[N] = 1;
    cache[N] = res;
  }
  return res;
}

void Main() {
  ll N;
  cin >> N;
  ll ans = 0;
  rep(i, N) {
    map<ll, ll> x = prime_factorize(i + 1);
    ll tmp = 1;
    for (auto a : x) {
      // cout << i + 1 << " " << a.first << " " << a.second << endl;
      tmp *= (a.second + 1);
    }
    ans += (i + 1) * tmp;
  }
  cout << ans << endl;
}

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


#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static void getval(_T &a) { std::cin >> a; }
template <class _T> static void getval(_T &a, _T &b) { std::cin >> a >> b; }
template <class _T> static void getval(_T &a, _T &b, _T &c) {
  std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
  if (a < (_T)0) {
    a *= (_T)-1;
  }
  return a;
}
template <class _T> static void tp_swap(_T &right, _T &left) {
  //	usage:  tp_swap<type name>(a, b);
  _T tmp = right;
  right = left;
  left = tmp;
}

static void exec();

int main() {
  exec();
  fflush(stdout);
  return 0;
}

static void exec() {
  int N;
  getval(N);

  std::vector<LLONG> divisor(N + 1, 0);
  for (int k = 1; k <= N; k++) {
    for (int m = k; m <= N; m += k) {
      divisor[m]++;
    }
  }
  LLONG ans = 0;
  for (int k = 1; k <= N; k++) {
    ans += k * divisor[k];
  }
  printf("%lld\\n", ans);
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static void getval(_T &a) { std::cin >> a; }
template <class _T> static void getval(_T &a, _T &b) { std::cin >> a >> b; }
template <class _T> static void getval(_T &a, _T &b, _T &c) {
  std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
  if (a < (_T)0) {
    a *= (_T)-1;
  }
  return a;
}
template <class _T> static void tp_swap(_T &right, _T &left) {
  //	usage:  tp_swap<type name>(a, b);
  _T tmp = right;
  right = left;
  left = tmp;
}

static void D();

int main() {
  D();
  fflush(stdout);
  return 0;
}

static void divisor(int targ, std::vector<int> &ans) {
  for (LLONG i = 1; i * i <= targ; i++) {
    if (targ % i == 0) {
      ans.push_back(i);
      if (i * i != targ) {
        ans.push_back(targ / i);
      }
    }
  }
}

static void D() {
  int N;
  getval(N);

  LLONG ans = 0;
  for (LLONG k = 1; k <= N; k++) {
    std::vector<int> div;
    divisor(k, div);
    ans += k * (div.size());
  }
  printf("%lld\\n", ans);
}
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 sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> f;
void g(int n) {
  f.resize(n + 1);
  f = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      f[j]++;
    }
  }
  return;
}

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

  g(n);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * f[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;
typedef long long ll;
const int inf = 1001001001;

ll f(ll n) {
  // vector<long long> ret;
  ll ret = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      // ret.push_back(i);
      ret++;
      if (i * i != n) {
        ret++;
        // ret.push_back(n / i);
      }
    }
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i < n + 1; i++) {
    ans += i * f(i);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define INF (int)1e9
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
ll n;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);

  cin >> n;
  vll a(n + 1);
  for (ll i = 1; i <= n; ++i)
    for (ll j = i; j <= n; j += i)
      ++a[j];

  ll ans = 0;
  for (ll i = 1; i <= n; ++i)
    ans += (a[i]) * i;

  cout << ans << '\\n';
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define INF (int)1e9
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
ll a[mxN];
ll n;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);

  cin >> n;
  for (ll i = 1; i <= n; ++i)
    for (ll j = i; j <= n; j += i)
      ++a[j];

  ll ans = 0;
  for (ll i = 1; i <= n; ++i)
    ans += (a[i]) * i;

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

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

int main() {
  long long n, s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    s += n / i * (n / i + 1) / 2 * i;
  cout << s << endl;
}

Error: TLE

Fixed submission:

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

#define ll long long
#define FOR(i, a, b) for (int i = a; i <= (int)(b); i++)

int main() {
  int N;
  ll S = 0;
  cin >> N;
  FOR(j, 1, N) {
    ll i = 2, a = 1;
    ll n = j;
    double sN = sqrt(n);
    map<int, int> v;
    for (; i <= sN; i += 2) {
      while (n % i == 0) {
        n /= i;
        v[i]++;
      }
      a *= (v[i] + 1);
      if (i == 2)
        i--;
      if (n == 1)
        break;
      sN = sqrt(n);
    }
    if (n > 1) {
      v[n] = 1;
      a *= 2;
    }
    S += j * a;
  }
  cout << S << endl;
}