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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long j = 1; j <= n; j++) {
    for (long long i = 1; i <= n; i++) {
      if (i % j == 0) {
        ans += i;
      }
    }
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

ll prime_count(ll n) {
  ll ans = 1;
  for (ll i = 2; i * i <= n; i++) {
    ll count = 1;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    ans *= count;
  }
  if (n != 1)
    ans *= 2;
  return ans;
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;

  return ret;
}

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main() {
  ll n;
  cin >> n;

  vector<ll> cnt(n + 1, 0);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      cnt[j]++;
    }
    ans += i * cnt[i];
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main() {
  ll n;
  cin >> n;

  map<ll, ll> mp;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      mp[j]++;
    }
    ans += i * mp[i];
  }

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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstddef>
#include <cstdint>
#include <iostream>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using P = pair<i64, i64>;
i64 elathos[(i64)(1e7) + 1];
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  i64 n;
  cin >> n;
  for (i32 i = 1; i <= n; i++) {
    for (i32 j = 1; i * j <= n; j++) {
      elathos[i * j]++;
    }
  }
  i64 ans = 0;
  for (i32 i = 1; i <= n; i++) {
    ans += i * elathos[i];
  }
  cout << ans << endl;
  /*for(i32 i = 1; i <= n; i++){
      cout << elathos[i] << " \\n"[i == n];
  }*/
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll, ll>;

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);
  rep(i, n) {
    ll A;
    cin >> A;
    a[i + 1] = a[i] + A;
  }
  rep(i, m) {
    ll B;
    cin >> B;
    b[i + 1] = b[i] + B;
  }
  ll ans = 0;
  rep(i, n + 1) {
    if (a[i] <= k) {
      auto Iter = upper_bound(b.begin(), b.end(), k - a[i]);
      ans = max(i + (Iter - b.begin()), ans);
    }
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll, ll>;

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll ans = 0;
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll k = floor(n / i);
    ans += k * (k + 1) * i / 2;
  }
  cout << ans << endl;
}

Error: -6
malloc(): unaligned tcache chunk detected


Fixed submission:

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll, ll>;
vector<ll> enum_divisors(ll N) {
  vector<ll> res;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  sort(res.rbegin(), res.rend());
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> mp(n + 1, 0);
  for (ll i = n; 1 <= i; i++) {
    if (mp[i])
      continue;
    vector<ll> v = enum_divisors(i);
    for (ll j = 0; j < v.size(); j++) {
      ans += (v.size() - j) * v[j];
      mp[v[j]]++;
    }
  }
  cout << ans << 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 < (int)(n); i++)
#define ll long long
#define P pair<int, int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
  ll n;
  cin >> n;
  vector<ll> 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 += i * a[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int, int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> pri;
  ans = 1;
  for (ll i = 2; i <= n; i++) {
    ll cnt = 1, ii = i;
    rep(j, pri.size()) {
      ll a = 1;
      rep(bi, INF) {
        if (ii % pri[j] != 0)
          break;
        ii /= pri[j];
        a++;
      }
      cnt *= a;
    }
    if (ii != 1)
      cnt *= 2;
    ans += i * cnt;
    if (cnt == 2) {
      pri.push_back(i);
      // cout << i << endl;
    }
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long ans = 0;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      ans += j;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int getNunbersFactorOfInt(int int_data) {
  set<int> S;
  for (int i = 1; i <= sqrt(int_data); i++)
    if (int_data % i == 0) {
      S.insert(i);
      S.insert(int_data / i);
    }
  return S.size();
}

int main() {
  int N;
  long long result = 1;
  cin >> N;
  for (int i = 2; i <= N; i++)
    result += i * getNunbersFactorOfInt(i);
  cout << result << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long cnt[10000005], x, ans;
int main() {
  cin >> x;
  for (int i = 1; i <= x; ++i)
    for (int j = i; j <= x; j += i)
      cnt[j]++;
  for (int i = 1; i <= x; ++i)
    ans += i * cnt[i];
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long su(long long n) {
  long long i, s, r;
  s = 1;
  for (i = 2; i * i <= n; i++) {
    r = 0;
    while (n % i == 0) {
      r++;
      n /= i;
    }
    if (r > 0) {
      r++;
      s *= r;
    }
  }
  if (n > 1)
    s *= 2; // 根号n右边的约数只能有一个质数 此时s*2.
  return s;
}
int main() {
  long long n, sum = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    sum += i * su(i);
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
typedef long long ll;

using namespace std;

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
typedef long long ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> f(n + 1);
  rrep(i, n) {
    int j;
    for (j = 1; j < sqrt((double)i); j++) {
      if (i % j == 0)
        f[i] += 2;
    }
    if (i == j * j)
      f[i]++;
  }
  ll ans = 0;
  rrep(i, n) { ans += i * f[i]; }
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
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;
}

ll a[10101010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int t = 1; i * t <= n; t++) {
      a[i * t]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
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;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n), B(m);
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];
  vector<ll> sa(n + 1, 0), sb(m + 1, 0);
  for (int i = 0; i < n; i++) {
    sa[i + 1] = sa[i] + A[i];
  }
  for (int i = 0; i < m; i++) {
    sb[i + 1] = sb[i] + B[i];
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (k - sa[i] < 0) {
      break;
    }
    ll t = k - sa[i];
    int size = upper_bound(all(sb), t) - sb.begin() - 1;
    ans = max(i + size, ans);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

signed main() {
  int N;
  cin >> N;
  vector<unsigned long long int> A(N);
  unsigned long long int ans = 0;
  for (int K = 1; K <= N; K++) {
    for (int i = 1; i <= N / K; i++) {
      A[K * i]++;
    }
  }
  for (int i = 1; i <= N; i++) {
    ans += A[i] * i;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

signed main() {
  int N;
  cin >> N;
  unsigned long long int count = 0;
  unsigned long long int ans = 0;
  for (int K = 1; K <= N; K++) {
    if (K == int(sqrt(K)) * int(sqrt(K))) {
      for (int i = 1; i <= sqrt(K); i++) {
        if (K % i == 0) {
          count++;
        }
      }
      count *= 2;
      count--;
    } else {
      for (int i = 1; i < sqrt(K); i++) {
        if (K % i == 0) {
          count++;
        }
      }
      count *= 2;
    }
    ans += count * K;
    count = 0;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll, ll> P;
typedef pair<double, ll> Pd;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;
typedef priority_queue<Pd, vector<Pd>, greater<Pd>> Pd_queue;

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e15;
const double DEL = 1e-6;
vec dx = {1, 0, -1, 0};
vec dy = {0, 1, 0, -1};

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a, b) a = (a + b) % mod

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  REP(i, 1, N + 1) {
    ll K = N / i;
    ans += K * (K + 1) * i / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll, ll> P;
typedef pair<double, ll> Pd;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;
typedef priority_queue<Pd, vector<Pd>, greater<Pd>> Pd_queue;

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e15;
const double DEL = 1e-6;
vec dx = {1, 0, -1, 0};
vec dy = {0, 1, 0, -1};

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a, b) a = (a + b) % mod

ll d[10000001];

ll Solve(ll A, ll x) {
  if (d[A] > 0)
    return d[A];
  if (A == 1)
    return d[A] = 1;
  for (ll i = x; i * i <= A; i++) {
    if (A % i == 0) {
      ll K = A, Count = 1;
      while (true) {
        if (K % i)
          break;
        K /= i;
        Count++;
      }
      return d[A] = Solve(K, i + 1) * Count;
    }
  }
  return d[A] = 2;
}

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

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

long long int NOD[10000100] = {};

long long int nod(long long int N) {
  // long long int NOD [N + 1] = {0};

  for (long long int i = 1; i <= N; i++) {
    for (long long int j = i; j <= N; j += i) {
      NOD[j] += 1;
    }
  }

  return NOD[N];
}

int main() {
  long long int n, i = 1, sum = 0, c;
  cin >> n;

  c = nod(n);

  while (i <= n) {

    // cout << c << endl;

    sum = sum + (i * NOD[i]);
    i++;
  }

  cout << sum;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, i = 1, sum = 0, divisor, j, c;
  cin >> n;

  while (i <= n) {

    c = 0;

    for (j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        c++;
      }
    }

    unsigned long long int z = sqrt(i);

    if (z == sqrt(i)) {
      c = (2 * c) - 1;
    }

    else {
      c = 2 * c;
      // cout << "*" << endl;
    }

    sum = sum + (i * c);
    i++;
  }

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589793

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589793

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    ll cnt = 0;
    for (ll j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (j == sqrt(i)) {
          cnt++;
        } else {
          cnt += 2;
        }
      }
    }
    sum += i * cnt;
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve() {
  ll n, cnt = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    for (ll j = i; j <= n; j += i)
      cnt += j;
  cout << cnt << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // ll t;cin>>t;while(t--)
  solve();
  return 0;
}


Error: TLE

Fixed submission:

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

int f(int n) {
  int total = 1;
  for (int p = 2; p <= sqrt(n); p++) {
    int count = 0;
    while (n % p == 0) {
      n = n / p;
      count++;
    }
    total = total * (count + 1);
  }
  if (n != 1)
    total *= 2;
  return total;
}

void solve() {
  int n;
  ll cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cnt += i * f(i);
  cout << cnt << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // ll t;cin>>t;while(t--)
  solve();
  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 = 0; i < n; i++)
using ll = long long;

int f(int x) { // 整数kの約数の個数
  int r = 1;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int cnt = 1;
      while (x % i == 0) {
        x /= i;
        cnt++;
      }
      r *= cnt;
    }
  }
  if (x != 1) {
    r *= 2;
  }
  return r;
}

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

Error: TLE

Fixed submission:

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

long f(long x) {
  long div = 0;
  for (long i = 1; i <= x; i++) {
    if (x % i == 0)
      div++;
  }
  return div;
}

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

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

int main() {
  int64_t N;
  cin >> N;
  int64_t C = 0;
  for (int64_t i = 1; i <= N; i++) {
    C += (i + (N - N % i)) * ((N - N % i) / i) / 2;
    // cout << C << endl;
  }
  cout << C << endl;
}

Error: -8

Fixed submission:

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

long long SUM(long long N) {
  if (N == 1) {
    // long long O = 1;
    return 1;
  }
  long long C = 0, S = 0;
  for (long long i = 0; i < N; i++) {
    if (N % i == 0) {
      C++;
    }
  }
  S = SUM(N - 1) + C * N;
  return S;
}

int main() {
  long long N;
  cin >> N;
  long long sum;
  sum = SUM(N);
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp make_pair
#define pb push_back
#define F first
#define pi 3.14159265358979323846
#define S second
#define ll long long
#define ld long double
#define sz(s) (ll) s.size()
#define vl vector<ll>
#define pll pair<ll, ll>
#define ml map<ll, ll>
#define mod 1000000007
#define MAXN 50005
#define mx 10000005
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define inv(i, a, b) for (ll i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
using namespace std;
ll a[mx] = {0};
void calc() {
  for (ll i = 2; i < mx; i++) {
    ll j = 2;
    while (j * i <= mx) {
      a[j * i]++;
      j++;
    }
  }
}
int main() {
  IOS;
  ll t, n, l;
  ll i, j, m, mn, d, x, y, ans = 0, temp = 0, k, c;
  string s, s1;
  cin >> n;
  //	l=sqrt(n);
  //	ll a[10000005];
  calc();
  ans = 1;
  rep(i, 2, n + 1) { ans += i * (a[i] + 2); }
  //	rep(i,1,n+1)ans+=i*a[i];
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp make_pair
#define pb push_back
#define F first
#define pi 3.14159265358979323846
#define S second
#define ll long long
#define ld long double
#define sz(s) (ll) s.size()
#define vl vector<ll>
#define pll pair<ll, ll>
#define ml map<ll, ll>
#define mod 1000000007
#define MAXN 50005
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define inv(i, a, b) for (ll i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
using namespace std;
ll calc(ll n) {
  ll i, ans = 0;
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      if (i * i == n)
        ans++;
      else
        ans += 2;
    }
  return ans + 2;
}
int main() {
  IOS;
  ll t, n, l;
  ll i, j, m, mn, d, x, y, ans = 0, temp = 0, k, c;
  string s, s1;
  cin >> n;
  // l=sqrt(n);
  ll a[10000005];

  ans = 1;
  rep(i, 2, n + 1) { ans += i * calc(i); }
  //	rep(i,1,n+1)ans+=i*a[i];
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, ans = 0;
  cin >> n;

  vector<ll> v(n + 1, 0);
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = 0; j < n + 1; j += i)
      v[j]++;
  }

  for (int f = 1; f <= n; f++) {
    ans += (f * (ll)v[f]);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:


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

// Function to print the divisors
long long int printDivisors(int n) {
  long long int ans = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal, print only one
      if (n / i == i)
        ans++;

      else // Otherwise print both
        ans = ans + 2;
    }
  }
  return ans;
}

/* Driver program to test above function */
int main() {
  long long int z, sum = 0;
  cin >> z;

  for (int i = 1; i <= z; i++) {
    long long int k;
    k = i * (printDivisors(i));
    sum += k;
  }
  cout << sum << endl;
  return 0;

  return 0;
}