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)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int N;
  cin >> N;
  vector<int> f(N + 1);
  FOR(i, 1, N + 1) {
    for (int j = i; j <= N; j += i) {
      f[j]++;
    }
  }
  ll res = 0;
  FOR(k, 1, N + 1) { res += (ll)k * f[k]; }
  cout << res << 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 - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<P> prime_fact(int n) {
  if (n == 1)
    return vector<P>(1, {1, 0});
  vector<P> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      res.rbegin()->second++;
      n /= i;
    }
  }
  if (n > 1)
    res.emplace_back(n, 1);
  return res;
}

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

  int N;
  cin >> N;
  vector<P> pf(N);
  ll res = 1;
  FOR(k, 2, N + 1) {
    vector<P> pf = prime_fact(k);
    ll f = 1;
    for (auto &p : pf) {
      f *= (p.second + 1);
    }
    res += k * f;
  }
  cout << res << endl;

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



#include <bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d", &n);
#define scl(n) scanf("%lld", &n);
#define scd(n) scanf("%lf", &n);
#define pf(res) printf("%d\\n", res);
#define pfl(res) printf("%lld\\n", res);
#define pfd(res) printf("%lf\\n", res);
#define maxii 10000005
using namespace std;
typedef pair<int, int> pii;
typedef pair<lln, lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

lln arr[maxii];
lln arr2[maxii];

int main() {
  lln n;
  scl(n) for (lln i = 1; i <= n; i++) arr[i] = 1;
  for (lln i = 2; i <= n; i++) {
    for (lln j = i; j <= n; j += i) {
      arr[j] = arr[j] + 1LL;
    }

    // arr[i]=((arr[i-1]+arr[i]));;
  }
  lln sum = 0;
  for (int i = 2; i <= n; i++) {
    lln sum1 = arr[i] * i;
    sum += sum1;
  }
  sum++;
  pfl(sum)
}


Error: TLE

Fixed submission:



#include <bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d", &n);
#define scl(n) scanf("%lld", &n);
#define scd(n) scanf("%lf", &n);
#define pf(res) printf("%d\\n", res);
#define pfl(res) printf("%lld\\n", res);
#define pfd(res) printf("%lf\\n", res);
#define maxii 4000
using namespace std;
typedef pair<int, int> pii;
typedef pair<lln, lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

lln arr[maxii];
bool prim[maxii];
int p = 0;
void prime() {
  for (int i = 3; i * i <= maxii; i += 2) {
    if (prim[i] == false) {
      for (int j = i * i; j <= maxii; j += i + i) {
        prim[j] = true;
      }
    }
  }
  arr[p++] = 2;
  for (lln i = 3; i <= maxii; i += 2) {
    if (prim[i] == false) {
      arr[p++] = i;
    }
  }
}

lln fun(lln n) {
  lln sum = 1;
  for (int i = 0; i < p && arr[i] * arr[i] <= n; i++) {
    if (n % arr[i] == 0) {
      lln cnt = 0;
      while (n % arr[i] == 0) {
        n /= arr[i];
        cnt++;
      }
      sum *= (cnt + 1);
    }
  }
  if (n != 1) {
    sum *= 2;
  }
  return sum;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  prime();
  lln n, sum = 0;
  scl(n);
  for (lln i = 1; i <= n; i++) {
    sum += (i * fun(i)) % 10000000000000;
  }
  cout << sum;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T> T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

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

signed main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int k = n / i;
    ans += (i + k * i) * k / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T> T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

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

signed main() {
  int n;
  cin >> n;
  map<int, int> m;
  repk(i, 1, n + 1) {
    int j = i;
    while (j <= n) {
      m[j]++;
      j += i;
    }
  }
  int sum = 0;
  repk(i, 1, n + 1) { sum += m[i] * i; }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
ll ans = 1, v[10000005];
int n, p[10000005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    v[i] = p[i] = i;
  for (int t = 2; t <= n; t++) {
    if (p[t] != 1) {
      ans += 2 * t;
      for (int s = t * 2; s <= n; s += t) {
        for (ll vi = v[s]; p[s] % t == 0; p[s] /= t, v[s] += vi)
          ;
      }
    } else
      ans += v[t];
  }
  printf("%lld\\n", ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
ll ans = 1;
vector<int> v[10000005];
int n;
int main() {
  scanf("%d", &n);
  for (int t = 2; t <= n; t++) {
    if (v[t].size() == 0) {
      ans += 2 * t;
      for (int s = t * 2; s <= n; s += t)
        v[s].push_back(t);
    } else {
      ll tmp = t;
      int u = t;
      for (int w : v[t]) {
        int x = 1;
        for (; u % w == 0; u /= w, x++)
          ;
        tmp *= x;
      }
      ans += tmp;
    }
  }
  printf("%lld\\n", ans);
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  ll N;
  cin >> N;

  vector<ll> A(N + 1, 0); // 約数の個数を入れる
  A[1] = 1;

  for (ll i = 2; i <= N; i++) {
    if (A[i] == 0) {
      ll p = i;
      //			cout << "prime " << p << endl;
      A[p] = 2;
      ll pp = p;
      while (pp * p <= N) {
        A[pp * p] = A[pp] + 1;
        //				cout << pp * p << endl;
        pp *= p;
      }
      for (int j = 2; j * p <= N; j++) {
        if (A[j] != 0) {
          pp = p;
          while (j * pp <= N) {
            if (A[j] != 0 && A[j * pp] == 0) {
              A[j * pp] = A[j] * A[pp];
              //						cout << j << ":"
              //<< A[j] << " " << pp << ":" << A[pp] << " " << j * pp << ":" <<
              //A[j*pp] << endl;
            }
            pp *= p;
          }
        }
      }
    }
  }

  ll cumm = 0;
  for (ll i = 1; i <= N; i++) {
    cumm += A[i] * i;
    //		cout << i << " " << A[i] << " " << cumm << endl;
  }
  cout << cumm << endl;
  return (0);
}


Error: 0

Fixed submission:

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

// sqrt(n) までの素数を列挙する。
//	nはllで入れるが、sqrt(n)はint範囲であること。
//	戻りはset<int> p, 特に素数はintで返す。
set<int> primes(ll n, bool flog = false) {
  int N = ((int)sqrt(n)) + 1;
  vector<bool> num(N, true);
  set<int> p;
  for (int i = 2; i < N; i++) {
    if (num[i]) {
      p.insert(i);
      if (flog)
        cout << "primes " << i << endl;
      for (int j = i; j < N; j += i) {
        num[j] = false;
      }
    }
  }
  return p;
}

int main() {

  int N;
  cin >> N;

  set<int> P = primes(N * N);

  vector<ll> A(N + 1, 0); // 約数の個数を入れる
  A[1] = 1;
  for (auto it = P.begin(); it != P.end(); it++) {
    int p = *it;
    ll pp = p;
    ll c = 1;
    while (pp <= N) {
      //			cout << pp << endl;
      for (int i = 1; i * pp <= N; i++) {
        if (A[i] != 0) {
          A[i * pp] = A[i] * (c + 1);
        }
      }
      pp *= p;
      c++;
    }
  }
  ll cumm = 0;
  for (int i = 1; i <= N; i++) {
    cumm += A[i] * i;
    //		cout << i << " " << A[i] << " " << cumm << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define debug printf("\\n<<CameHere<<\\n")
#define mem(x, y) memset(x, y, sizeof(x))
#define all(qz) qz.begin(), qz.end()
#define rall(qz) qz.rbegin(), qz.rend()
#define inf LLONG_MIN
#define INF LLONG_MAX
#define mod 1000000007
#define Sqr(x) ((x) * (x))
#define ll long long
#define mk make_pair
#define pb push_back
#define pi acos(-1.0)
#define cos(a) cos(a *pi / 180)
#define sin(a) sin(a *pi / 180)
#define tan(a) tan(a *pi / 180)

ll pow(ll c, ll d) { return d == 0 ?: c * pow(c, d - 1); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }
/*---------AL ASAD NUR RIYAD------------*/
#define mx 10000009
ll ar[mx + 100];

void fn() {
  for (ll i = 2; i <= mx / 2; i++) {
    for (ll j = i * 2; j <= mx; j += i) {
      ar[j]++;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  fn();
  ll n;
  cin >> n;
  ll cnt = 1;
  for (ll i = 2; i <= n; i++) {
    cnt += (i * (ar[i] + 2));
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define debug printf("\\n<<CameHere<<\\n")
#define mem(x, y) memset(x, y, sizeof(x))
#define all(qz) qz.begin(), qz.end()
#define rall(qz) qz.rbegin(), qz.rend()
#define inf LLONG_MIN
#define INF LLONG_MAX
#define mod 1000000007
#define Sqr(x) ((x) * (x))
#define ll long long
#define mk make_pair
#define pb push_back
#define pi acos(-1.0)
#define cos(a) cos(a *pi / 180)
#define sin(a) sin(a *pi / 180)
#define tan(a) tan(a *pi / 180)

ll pow(ll c, ll d) { return d == 0 ?: c * pow(c, d - 1); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }
/*---------AL ASAD NUR RIYAD------------*/
#define mx 20000009
ll ar[mx + 100];

void fn() {
  for (ll i = 2; i <= mx / 2; i++) {
    for (ll j = i * 2; j <= mx; j += i) {
      ar[j]++;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  fn();
  ll n;
  cin >> n;
  ll cnt = 1;
  for (ll i = 2; i <= n; i++) {
    cnt += (i * (ar[i] + 2));
  }
  cout << cnt << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>

const long long INF = 1e17 + 7;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

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

  vector<long long> a(n + 1, 0);
  for (long long i = 1; i <= n; i++) {
    int id = 1;
    while (1) {
      a[i * id]++;
      id++;
      if (i * id > n)
        break;
    }
  }

  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>

const long long INF = 1e17 + 7;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

long long f(long long x) {
  long long res = 0;
  for (long long i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res += 2;
      if (x / i == i) {
        res -= 1;
      }
    }
  }
  return res;
}

int main() {
  long long n;
  cin >> n;
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    cnt += i * f(i);
  }
  cout << cnt << 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;
using P = pair<int, int>;

int main() {
  ll N;
  cin >> N;
  int divisors[N + 1] = {0};
  for (int i = 1; i <= N; i++) {
    for (int j = 1; i * j <= N; ++j) {
      ++divisors[i * j];
    }
  }

  ll res = 0;
  for (int i = 1; i <= N; i++) {
    res += ll(i) * divisors[i];
  }
  cout << res << endl;

  return 0;
}


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

int main() {
  int N;

  int divisors[1 << 24];
  rep(i, 1 << 24) {
    for (int j = 1; i * j <= N; ++j) {
      ++divisors[i * j];
    }
  }

  ll res = 0;
  rep(i, N + 1) { res += ll(i) * divisors[i]; }
  cout << res << endl;

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

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

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int arr[n + 1];
  fill(arr, arr + n + 1, 0);
  for (long long int i = 1; i <= n; i++) {
    for (long long int k = i; k <= n; k += i) {
      arr[k]++;
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    ans += i * arr[i];
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

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

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int arr[n + 1];
  arr[0] = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int divisor = 0;
    for (long long int k = 1; k <= sqrt(i); k++) {
      if (i % k == 0) {
        if (i / k != k)
          divisor += 2;
        else {
          divisor++;
        }
      }
    }
    arr[i] = divisor;
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    ans += i * arr[i];
  }
  cout << ans << "\\n";
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

using namespace std;
typedef long long llong;

#define MAX

int main() {
  llong N;

  llong ans = 0;
  scanf("%lld", &N);

  for (llong x = 1; x <= N; x++) {
    llong n = N / x;
    ans += n * (2 * x + (n - 1) * x) / 2;
  }

  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

using namespace std;
typedef long long llong;

#define MAX

int main() {
  int N;

  llong ans = 0;
  scanf("%lld", &N);

  for (llong x = 1; x <= N; x++) {
    llong n = N / x;
    ans += n * (2 * x + (n - 1) * x) / 2;
  }

  printf("%lld\\n", ans);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    rep(k, i) {
      if ((i % k) == 0)
        ans += 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++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll> A(10000000);
  for (ll i = 1; i <= 10000000; i++) {
    for (ll j = 1; i * j <= 10000000; j++) {
      A[i * j]++;
    }
  }
  ll ans = 0;
  rep(i, N + 1) { ans += i * A[i]; }
  cout << ans;
}

Error: TLE

Fixed submission:

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

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() {
  ll N = 0, ans = 0;
  cin >> N;
  rep(i, N) {
    ll tmp = 1;
    const auto &res = prime_factorize(i + 1);
    for (auto p : res) {
      tmp *= (p.second + 1);
    }
    ans += tmp * (i + 1);
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll power(ll x, ll n, ll mod = md) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    n = (n >> 1);
    x = (x * x) % mod;
  }
  res %= mod;
  return res;
}

void sieve(vector<ll> &primes, ll lim) {
  vector<bool> prime(lim + 1, true);
  for (int i = 2; i * i <= lim; i++) {
    if (prime[i]) {
      for (int j = 2; j * i <= lim; j++) {
        prime[j * i] = false;
      }
    }
  }
  primes.push_back(2);
  for (int i = 3; i <= lim; i += 2) {
    if (prime[i]) {
      primes.push_back(i);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, res = 0;
  vector<ll> f(1e7 + 1, 1);
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll x = i, fi = 1;
    if (i != 1) {
      for (int j = i; j <= n; j += i) {
        f[j]++;
      }
    }
    res += i * f[i];
  }
  cout << res << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

ll power(ll x, ll n, ll mod = md) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    n = (n >> 1);
    x = (x * x) % mod;
  }
  res %= mod;
  return res;
}

void sieve(vector<ll> &primes, ll lim) {
  vector<bool> prime(lim + 1, true);
  for (int i = 2; i * i <= lim; i++) {
    if (prime[i]) {
      for (int j = 2; j * i <= lim; j++) {
        prime[j * i] = false;
      }
    }
  }
  primes.push_back(2);
  for (int i = 3; i <= lim; i += 2) {
    if (prime[i]) {
      primes.push_back(i);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<ll> p;
  sieve(p, 3162);
  int pn = p.size();
  ll n, res = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll x = i, fi = 1;
    for (int j = 0; j < pn && p[j] * p[j] <= x; j++) {
      int cnt = 0;
      while (x % p[j] == 0) {
        x /= p[j];
        cnt++;
      }
      fi *= (cnt + 1);
    }
    if (x > 1) {
      fi *= 2;
    }
    res += i * fi;
  }
  cout << res << "\\n";
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 1;
int n, m, k;
long long int cs[N];
int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      cs[j]++;
    sum += 1LL * i * cs[i];
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
int n, m, k;
long long int A[N], B[N], cs[N], sum;
int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      cs[j]++;
    sum += 1LL * i * cs[i];
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  ll ans = 1;
  ll N;
  cin >> N;

  vector<ll> is_prime(N + 1, 1);

  for (int i = 2; i <= N; i++) {
    if (is_prime[i] == 1) {
      for (int j = 2 * i; j <= N; j += i) {
        int tmp = j, mul = 2;
        while (tmp % i == 0) {
          tmp /= i;
          mul++;
        }
        if (tmp == 1)
          is_prime[j] = mul - 1;
        else
          is_prime[j] *= mul - 1;
      }
      is_prime[i] = 2;
      // cout << is_prime[i];
    }
    // cout << i << is_prime[i] << endl;
    ans += i * is_prime[i];
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;

std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::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.push_back(i);
    }
  }
  return P;
}

int main() {
  ll ans = 0;
  ll N;
  cin >> N;
  vector<int> primes;
  primes = Eratosthenes(N);

  int pos = 0;
  primes.push_back(100000000);

  for (int i = 1; i <= N; i++) {
    if (primes[pos] == i) {
      ans += i * 2;
      pos++;
      continue;
    }
    int fk = 1, cnt = 0, num = i, div = 0, step = 1;
    while (num >= 2) {
      if (num < primes[div])
        break;
      cnt = 0;

      while (num % primes[div] == 0) {
        num /= primes[div];
        cnt++;
      }
      fk *= cnt + 1;
      div++;
    }
    ans += i * fk;
  }
  cout << ans << endl;

  return 0;
}