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

#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL << ((ll)n))
#define SUBS(s, f, t) ((s).substr((f), (t) - (f)))
#define ALL(a) (a).begin(), (a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
vi ans(11111111, 1);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j < 11111111; j += i) {
      ans[j]++;
    }
  }
  ll an = 0;
  for (int i = 1; i <= n; i++) {
    an += i * ans[i];
  }
  cout << an << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL << ((ll)n))
#define SUBS(s, f, t) ((s).substr((f), (t) - (f)))
#define ALL(a) (a).begin(), (a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
vi ans(1111111, 1);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j < 1111111; j += i) {
      ans[j]++;
    }
  }
  ll an = 0;
  for (int i = 1; i <= n; i++) {
    an += i * ans[i];
  }
  cout << an << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;
typedef long long ll;

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

  return 0;
}

Error: 0

Fixed submission:


#include <bits/stdc++.h>
#include <map>
using namespace std;
map<string, long long int> mp;
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) {
      // 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]) {

      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;
}

long long int solve(long long int n) {
  string str = to_string(n);
  if (n == 0)
    return 0;
  if (mp.find(str) != mp.end())
    return mp[str];
  return mp[str] = solve(n - 1) + n * countDivisors(n);
}

int main() {

  long long int n;
  cin >> n;
  // long long int sum=0;

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

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout << "Case #" << i + 1 << " :";
#define s(n) scanf("%d", &n)
#define rev(i, n) for (int i = n; i >= 0; --i)
#define REV(i, a, b) for (int i = a; i >= b; --i)
#define miN(a, b) (((a) < (b)) ? (a) : (b))
#define sc(n) scanf("%c", &n)
#define tr(c, i) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define INF 1000000000
#define pii pair<long long int, long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
#define MAXN 10000001
int spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)
    spf[i] = i;
  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;
  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
ll getFactorization(int x) {
  ll ret = 1;
  while (x != 1) {
    int a = spf[x];
    int b = 1;
    while (spf[x] == a) {
      x = x / spf[x];
      b++;
    }
    ret *= b;
  }
  return ret;
}
void pre() {}
void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += getFactorization(i) * i;
  }
  cout << ans << "\\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  pre();
  sieve();
  long long int num = 1;
  // cin>>num;
  for (long long int i = 0; i < num; i++) {
    solve();
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout << "Case #" << i + 1 << " :";
#define s(n) scanf("%d", &n)
#define rev(i, n) for (int i = n; i >= 0; --i)
#define REV(i, a, b) for (int i = a; i >= b; --i)
#define miN(a, b) (((a) < (b)) ? (a) : (b))
#define sc(n) scanf("%c", &n)
#define tr(c, i) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define INF 1000000000
#define pii pair<long long int, long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre() {}
vector<int> arr[10000001];
void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (ll j = 1; j * i <= n; j++) {
      arr[i * j].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += arr[i].size() * i;
  }
  cout << ans << "\\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  pre();
  long long int num = 1;
  // cin>>num;
  for (long long int i = 0; i < num; i++) {
    solve();
  }
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MAXN 10000002
const ll M = 1e9 + 7, N = 1e6 + 5;

ll spf[MAXN];

void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;

  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)

        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

map<ll, ll> getFactorization(ll x) {
  map<ll, ll> mp;
  while (x != 1) {
    mp[spf[x]]++;
    x = x / spf[x];
  }
  return mp;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  sieve();
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    map<ll, ll> mp = getFactorization(i);
    ll cnt = 1;
    for (auto i : mp)
      cnt *= (i.second + 1);
    ans += i * cnt;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 1e6 + 5;

map<ll, ll> factorize(ll x) {
  map<ll, ll> m;
  for (ll i = 2; i * i <= x; ++i)
    while (x % i == 0)
      m[i]++, x /= i;
  if (x > 1)
    m[x]++;
  return m;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    map<ll, ll> mp = factorize(i);
    ll cnt = 1;
    for (auto i : mp)
      cnt *= (i.second + 1);
    ans += i * cnt;
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded


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

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define sq(x) (x) * (x)
#define PI acos(-1.0)
#define all(x) x.begin(), x.end()
#define nl '\\n'

typedef long long int ll;
typedef unsigned long long int llu;

int main() {
  ll ans = 0, n;
  cin >> n;
  ll A[n + 1] = {};
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i) {
      A[j]++;
    }
  }

  for (int i = 1; i <= n; i++) {
    ans += A[i] * i;
  }
  cout << ans << nl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, ans = 0, i, j, c;
  cin >> t;
  for (i = 1; i <= t; i++) {
    c = 0;
    for (j = 2; j <= i / 2; j++) {
      if (i % j == 0)
        c++;
    }
    if (i == 1)
      c += 1;
    else
      c += 2;
    ans += i * c;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

ll a[_max];

void init() {

  for (int i = 1; i <= _max; i++) {
    int begin = i;
    while (1) {
      if (begin > _max) {
        break;
      }
      a[begin]++;
      begin = begin + i;
    }
  }
}

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

Error: TLE

Fixed submission:

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

ll a[_max];

int init() {

  for (int i = 1; i <= _max; i++) {
    int begin = i;
    while (1) {
      if (begin > _max) {
        break;
      }
      a[begin]++;
      begin = begin + i;
    }
  }
}

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

#include <bits/stdc++.h>
#define FOR(i, start, end) for (int i = start; i <= end; i++)
#define ll long long

using namespace std;

int main(void) {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> e(n + 1, 0);

  FOR(i, 1, n) {
    for (int j = i; j <= n; j += i) {
      e[j]++;
    }
  }
  FOR(i, 1, n) ans += i * e[i];

  cout << ans << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, start, end) for (int i = start; i <= end; i++)
#define ll long long

using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> e(n + 1, 0);
  ll ans = 0;
  FOR(i, 1, n) {
    for (int j = i; i <= n; j += i) {
      e[j]++;
    }
  }
  FOR(i, 1, n) ans += i * e[i];

  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define FOR(i, start, end) for (int i = start; i <= end; i++)

using namespace std;

int main(void) {
  // Your code here!
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> e(n + 1, 0);
  FOR(i, 1, n) {
    for (int j = i; j <= n; j += i) {
      e[j]++;
    }
  }
  FOR(i, 1, n) ans += i * e[i];
  cout << ans << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, start, end) for (int i = start; i <= end; i++)
#define ll long long

using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> e(n + 1, 0);
  ll ans = 0;
  FOR(i, 1, n) {
    for (int j = i; i <= n; j += i) {
      e[j]++;
    }
  }
  FOR(i, 1, n) ans += i * e[i];

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

#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <unordered_map>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const ll N = 1e10;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int cnt[10000001];
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      ans += j;
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <unordered_map>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const ll N = 1e10;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int ans[200];

void add(int *a, ll b) {
  int carry = 0;
  for (int i = 0; i < 200; i++) {
    ans[i] += (b % 10) + carry;
    b /= 10;
    carry = ans[i] / 10;
    ans[i] %= 10;
  }
}
int divn[10000000];
int main() {
  ans[0] = 1;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j * i <= n; j++) {
      if (j * i <= n) {
        int subs = j * i;
        divn[subs]++;
      }
    }
  }

  ll addnum = 0;
  for (int i = 2; i <= n; i++) {
    addnum = divn[i] * i;
    add(ans, addnum);
  }

  bool flag = true;
  for (int i = 199; i >= 0; i--) {
    if (flag) {
      if (ans[i] != 0) {
        flag = false;
        cout << ans[i];
      }
    } else
      cout << ans[i];
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
// #define goodset tree<pa, null_type, less<pa>, rb_tree_tag,
// tree_order_statistics_node_update>
#define FRE                                                                    \\
  freopen("acm.in", "r", stdin);                                               \\
  freopen("acm.out", "w", stdout);

const ll mod = 1000000007;
const ll N = 1e6 + 5;
int main() {
  FAST ll tc, i, j;
  // cin>>tc;
  tc = 1;
  while (tc--) {
    ll n;
    cin >> n;
    ll ans = 0;
    for (i = 1; i <= n; i++) {
      for (j = i; j <= n; j += i)
        ans += j;
    }
    cout << ans << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

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

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
// #define goodset tree<pa, null_type, less<pa>, rb_tree_tag,
// tree_order_statistics_node_update>

const ll mod = 1000000007;
const ll N = 1e7 + 1;

ll siv[N], ans[N], siv1[N];
int main() {
  FAST ll tc, i, j;
  // cin>>tc;
  tc = 1;
  for (i = 2; i * i < N; i++) {
    if (siv[i] == 0) {
      for (j = i * i; j < N; j += i)
        siv[j] = 1;
    }
  }
  vector<ll> v;
  for (i = 2; i < N; i++) {
    if (siv[i] == 0) {
      v.pb(i);
      // cout<<i<<"\\n";
    }
    // cout<<i<<"\\n";
  }
  for (j = 0; j < v.size(); j++) {
    if (v[j] * v[j] > 1e7)
      break;
    siv1[v[j] * v[j]] = 1;
  }
  ans[1] = 1;
  for (i = 2; i < N; i++) {
    ll ansind = 1, te = i;
    for (j = 0; j < v.size(); j++) {
      if (v[j] * v[j] * v[j] > te)
        break;
      ll cnt = 1;
      while (te % v[j] == 0) {
        te /= v[j];
        cnt++;
      }
      ansind *= cnt;
    }
    if (te > 1) {
      if (siv[te] == 0)
        ansind *= 2;
      else if (siv1[te])
        ansind *= 3;
      else if (te != 1)
        ansind *= 4;
    }
    // cout<<ansind<<"\\n";
    ansind *= i;
    ans[i] = ansind;
  }
  for (i = 2; i < N; i++)
    ans[i] += ans[i - 1];
  while (tc--) {
    ll n;
    cin >> n;
    cout << ans[n];
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1 << 30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

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

  llong n;
  cin >> n;

  llong ans = 0;
  for (llong i = 1; i <= n; ++i) {
    llong k = n / i;
    ans += k * (2 * i + (k - 1) * i) / 2;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1 << 30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template <typename T> llong factorization(T p) {
  llong i = 2;
  map<llong, llong> M;
  while (i * i <= p) {
    if (p % i == 0) {
      ++M[i];
      p /= i;
    } else {
      ++i;
    }
  }

  if (p != 1)
    ++M[p];

  llong cnt = 1;
  for (map<llong, llong>::iterator itr = M.begin(); itr != M.end(); ++itr) {
    cnt *= itr->second + 1;
  }

  return cnt;
}

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

  llong n;
  cin >> n;
  llong ans = 0;
  for (llong k = 1; k <= n; ++k)
    ans += k * factorization(k);
  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 < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> d(10000001, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      d.at(j)++;
  }
  ll ans = 0;
  for (int i = 0; i < 10000001; i++)
    ans += (ll)i * d.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;
const int INF = 1001001001;

int divisors(int n) {
  set<int> s;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      s.insert(i);
      s.insert(n / i);
    }
  }
  return (int)s.size();
}

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

#include <bits/stdc++.h>
#define int long long
using namespace std;
int fl[10000011], prm[10000011], sz = 0, spf[10000011], ar[10000011],
                                 a2[10000001];
void sieve() {
  int mx = sqrt(10000001);
  for (int i = 1; i <= 10000001; i++)
    spf[i] = i;
  fl[1] = 1;
  fl[0] = 1;
  spf[2] = 2;
  for (int i = 4; i <= 10000001; i += 2) {
    fl[i] = 1;
    spf[i] = 2;
  }
  for (int i = 3; i <= 10000001; i += 2) {
    if (!fl[i]) {
      if (i > mx)
        continue;
      for (int j = i * i; j <= 10000001; j += (i * 2)) {
        fl[j] = 1;
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
  /*for(int i = 1 ; i <= 10000000 ; i++)
  {
      for(int j = i ; j <= 10000000 ; j+=i)
      {
          v[j]
      }
  }*/
}
int32_t main() {
  sieve();
  int n;
  int ans = 0;
  scanf("%lld", &n);
  for (int k = 1; k <= n; k++) {
    // cout<<k<<endl ;
    int s = 1;
    int p = k;
    set<int> st;
    while (p != 1) {
      int x = spf[p];
      st.insert(x);
      ar[x]++;
      p /= x;
    }
    for (auto x : st) {
      int p = ar[x];
      ar[x] = 0;
      s *= (p + 1);
    }
    ans += (k * s);
  }
  printf("%lld\\n", ans);
}
// 10000000


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int fl[10000001], prm[10000001], sz = 0, spf[10000001], ar[10000001],
                                 a2[10000001];
void sieve() {
  int mx = sqrt(10000011);
  for (int i = 1; i <= 10000001; i++)
    spf[i] = i;
  fl[1] = 1;
  fl[0] = 1;
  spf[2] = 2;
  for (int i = 4; i <= 10000001; i += 2) {
    fl[i] = 1;
    spf[i] = 2;
  }
  for (int i = 3; i <= 10000001; i += 2) {
    if (!fl[i]) {
      if (i > mx)
        continue;
      for (int j = i * i; j <= 10000001; j += (i * 2)) {
        fl[j] = 1;
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
  /*for(int i = 1 ; i <= 10000000 ; i++)
  {
      for(int j = i ; j <= 10000000 ; j+=i)
      {
          v[j]
      }
  }*/
}
int32_t main() {
  sieve();
  int n;
  ll ans = 0;
  scanf("%d", &n);
  for (int k = 1; k <= n; k++) {
    // cout<<k<<endl ;
    ll s = 1;
    int p = k;
    set<int> st;
    while (p != 1) {
      int x = spf[p];
      st.insert(x);
      ar[x]++;
      p /= x;
    }
    for (auto x : st) {
      int p = ar[x];
      ar[x] = 0;
      s *= (p + 1);
    }
    ans += (k * s);
  }
  printf("%lld\\n", ans);
}
// 10000000
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

ll func(ll x) {
  ll r = 1;
  for (ll i = 2; i * i <= x; i++) {
    if (x % i != 0)
      continue;
    ll cnt = 0;
    while (x % i == 0) {
      x /= i;
      cnt++;
    }
    r *= cnt + 1;
  }
  if (x != 1)
    r *= 2;
  return r;
}

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;

const ll INF = 1e18;
const int MOD = 1e9 + 7;

int main() {

  ll n, ans = 0;
  cin >> n;

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;

const ll INF = 1e18;
const int MOD = 1e9 + 7;

ul numberOfDivisors(int n) {

  ul cnt = 0;
  int lim = int(sqrt(n));

  for (int i = 1; i <= lim; ++i) {
    if (n % i == 0)
      cnt += 2;
  }

  if (double(sqrt(n)) == lim)
    --cnt;
  return cnt;
}

int main() {

  int N;
  cin >> N;
  ul ans = 0;

  for (int i = 1; i <= N; ++i) {
    ans += numberOfDivisors(i) * (unsigned long)(i);
  }

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