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

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

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


Error: TLE

Fixed submission:

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

#define MAX 4000
vector<int> p;
vector<bool> p_table(MAX + 1, true);
void prime() {
  p_table[0] = false, p_table[1] = false;
  for (int i = 2; i <= MAX; i++) {
    if (p_table[i]) {
      p.push_back(i);
      for (int j = 2; i * j <= MAX; j++) {
        p_table[i * j] = false;
      }
    }
  }
}

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

  prime();
  int n = p.size();
  for (ll i = 1; i <= N; i++) {
    vector<ll> count(n, 1);
    int j = 0;
    ll num = i;
    ll K = 1;
    while (num > 1) {
      if (j == n) {
        K *= 2;
        break;
      }
      if (num % p[j] == 0) {
        num /= p[j];
        count[j]++;
      } else {
        j++;
      }
    }
    for (int k = 0; k < n; k++) {
      K *= count[k];
    }
    ans += i * K;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
typedef long long ll;
using namespace std;

int main() {
  ll N;

  ll ans = 0;
  // ll ans_tmp;

  cin >> N;

  // int f[N + 1];
  // int f;
  // int f_tmp;

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

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
typedef long long ll;
using namespace std;

int main() {
  int N;

  ll ans = 0;
  // ll ans_tmp;

  cin >> N;

  // int f[N + 1];
  // int f;
  // int f_tmp;

  for (int i = 1; i < N + 1; i++) {
    // f = 0;
    for (int j = 1; j < i + 1; j++) {
      if (i % j == 0)
        ans += i;
    }
    // ans += i * f;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int main() {
  ll n, sum = 0;
  cin >> n;

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

  for (int i = 1; i <= n; i++)
    sum += i * b[i];

  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int main() {
  ull n, sum = 0, c = 0;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    c = 0;
    for (int j = 1; j <= i / 2; j++)
      if (i % j == 0)
        c++;
    sum += i * (c + 1);
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  lli n;
  cin >> n;

  if (n == 1) {
    cout << 1;
    return 0;
  }
  lli sum = 0;
  for (lli x = 1; x <= n; x++) {
    lli y = (n / x);
    lli tmp = (y * (y + 1) * x) / 2;
    sum += tmp;
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define M 1000000009
#define maxN 1000000

void solve() {
  lli n;
  cin >> n;
  lli sum = 0;
  for (lli k = 1; k <= n; k++) {
    if (k == 1)
      sum += 1;
    else {
      lli count = 0;
      for (lli i = 1; i * i <= k; i++) {
        if (k % i == 0) {
          if (k / i == i)
            count++;
          else
            count = count + 2;
        }
      }
      // cout << "k: " << k << "   count:" << count << "\\n";
      sum += (count * k);
    }
  }
  cout << sum << "\\n";
}

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

  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll N;
  cin >> N;
  ll x = 0;
  vector<ll> div(10000000, 0);

  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; i * j <= N; j++) {
      div[i * j]++;
    }
  }

  for (ll k = 1; k <= N; k++) {
    x += k * div[k];
  }
  cout << x << endl;
}

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


Fixed submission:

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

int main() {
  ll N;
  cin >> N;
  ll x = 0;
  vector<ll> div(10000000000, 0);

  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; i * j <= N; j++) {
      div[i * j]++;
    }
  }

  for (ll k = 1; k <= N; k++) {
    x += k * div[k];
  }
  cout << x << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  for (ll x = 1; x <= N; ++x) {
    ll y = N / x;
    ans += x * (1 + y) * y / 2;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

template <typename T> void divisor(T n, vector<T> &divisors) {
  T root_n = (T)sqrt(n);
  for (int i = 1; i <= root_n; ++i) {
    if (n % i == 0) {
      divisors.push_back(i);
      if (n / i != i)
        divisors.push_back(n / i);
    }
  }
}

template <typename T> void furui(T n, vector<T> &primes) {
  primes.push_back(2);
  primes.push_back(3);
  for (int i = 5; i < n; i += 2) {
    bool is_prime = true;
    for (auto p : primes) {
      if (i % p == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime)
      primes.push_back(i);
  }
}

template <class T> void printIter(const T &a, string delimiter) {
  if (a.size() == 0)
    return;
  auto it = a.begin();
  cout << *it;
  it++;
  while (it != a.end()) {
    cout << delimiter << *it;
    it++;
  }
  cout << endl;
}

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  vector<int> primes;
  vector<unordered_map<int, int>> ms(N + 1);
  furui((int)sqrt(N) + 1, primes);
  for (int i = 1; i <= N; ++i) {
    int temp = i;
    unordered_map<int, int> m;
    for (auto p : primes) {
      if (temp < p * p)
        break;
      if (temp % p == 0) {
        temp /= p;
        m = ms[temp];
        m[p]++;
        break;
      }
    }
    if (i != 1 && temp == i)
      m[i]++;
    ms[i] = m;
    ll n = 1;
    for (auto pair : m) {
      n *= pair.second + 1;
    }
    ans += i * n;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  i64 N;
  cin >> N;
  vector<i64> cnt(N + 1);
  for (i64 i = 1; i <= N; i++)
    for (i64 j = 1; i * j <= N; j++)
      cnt[i * j]++;
  i64 ans = 0;
  for (i64 i = 1; i <= N; i++)
    ans += cnt[i] * i;
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  i64 N;
  cin >> N;
  i64 ans = 1;
  vector<map<i64, i64>> cnt(N + 1);
  vector<i64> memo(N + 1);
  memo[1] = 1;
  for (i64 i = 2; i <= N; i++) {
    i64 t = i;
    for (i64 j = 2; j * j <= i; j++) {
      if (i % j != 0)
        continue;
      cnt[i] = cnt[i / j];
      t = j;
      break;
    }
    cnt[i][t]++;
    memo[i] = memo[i / t] / (cnt[i][t] == 0 ? 1 : cnt[i][t]) * (cnt[i][t] + 1);
    ans += memo[i] * i;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll M = 1000010;

int main() {
  ll N, ans = 0;
  set<ll> st;

  cin >> N;
  vector<ll> f(N + 1);

  for (ll x = 1; x <= N; x++) {
    f[x] = x * (N / x) * (N / x + 1) / 2;
    ans += f[x];
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll M = 1000010;

int main() {
  ll N, ans = 0;
  set<ll> st;

  cin >> N;
  vector<ll> f(N + 1);

  for (ll i = 1; i <= N; i++) {
    for (ll j = i; j <= N; j++) {
      if (j % i == 0)
        f[j]++;
    }
  }

  for (ll x = 1; x <= N; x++) {
    ans += x * f[x];
  }

  cout << ans << endl;

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

/**
 *    author:  yuya1234
 *    created: 30.06.2020 11:42:41
 **/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define SORT(s) sort((s).begin(), (s).end())
#define SORTD(s) sort((s).rbegin(), (s).rend())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

// 初項:a, 公差:a で, 上限:lim の数列の総和を返す関数
ll sn(ll a, ll lim) {
  ll n = lim / a;         // 項数:n  =  上限:lim / 公差:a
  ll l = n * a;           // 末項:l  =  項数:n   * 公差:a
  return (a + l) * n / 2; // 総和:sn = (初項:a   + 末項:l) * 項数:n / 2
}

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

  int n;
  cin >> n;

  ll ans = 0;
  // FOR(i,1,n)
  // {
  //     FOR(j,1,n)
  //     {
  //         if(i%j==0)ans+=i;
  //     }
  // }

  FOR(i, 1, n) { ans += sn(i, n); }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

/**
 *    author:  yuya1234
 *    created: 27.06.2020 20:57:38
 **/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(x.begin(), x.end())
#define SORTD(x) sort(x.rbegin(), x.rend())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))
ll divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(), ret.end()); // 昇順に並べる
  return SZ(ret);
}

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

  int n;
  cin >> n;

  ll ans = 0;
  FOR(i, 1, n) { ans += divisor(i) * i; }

  cout << ans << endl;

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

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;

ll a[10000001], b[10000001];
int main() {
  ll n;
  cin >> n;

  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      a[j]++;
    }
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;

ll check(ll n) {
  ll cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

// エラトステネスのふるい
/*
int MAX=101010;
vector<int> is_prime(MAX,1);
is_prime[0]=0,is_prime[1]=0;
for(int i=2;i<MAX;i++){
    if(!is_prime[i]) continue;
    for(int j=i*2;j<MAX;j+=i) is_prime[j]=0;
}*/

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

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      ans += j;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

// 素因数分解 O(√n)
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
// 素因数の個数はlogn
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll p = 2; p * p <= n; p++) {
    if (n % p != 0)
      continue;
    int num = 0; // 指数
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back({p, num});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

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

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    auto pf = prime_factorize(i);
    ll tmp = 1;
    for (auto p : pf) {
      tmp *= (p.second + 1);
    }
    ans += i * tmp;
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

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

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define deb(x) cout << #x << " - " << x << "\\n";
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define D2(x)                                                                  \\
  cout << "[" << #x << ": ";                                                   \\
  for (auto it : x)                                                            \\
    cout << it << " ";                                                         \\
  cout << "]\\n";
#define D2p(x)                                                                 \\
  cout << #x << " ~ [ ";                                                       \\
  for (auto n : x)                                                             \\
    cout << n.first << "-" << n.second << " / ";                               \\
  cout << "]"                                                                  \\
       << "\\n";
#define ps(x, y) fixed << setprecision(y) << x

#define PI 3.141592653589793238462643383279502884L
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 1e5 + 2;

int prime[10000002];
void SieveOfEratosthenes(int n) {
  memset(prime, -1, sizeof(prime));
  prime[1] = 1;
  for (int p = 2; p <= n; p++) {
    if (prime[p] == -1) {
      for (int i = p; i <= n; i += p)
        if (prime[i] == -1)
          prime[i] = p;
    }
  }
}

int main() {
  IOS;
  SieveOfEratosthenes(10000001);
  int n;
  cin >> n;
  ll sum = 0, pro, cnt, y;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    pro = 1;
    while (x != 1) {
      y = prime[x];
      cnt = 0;
      while (x % y == 0) {
        x /= y;
        ++cnt;
      }
      pro *= (cnt + 1);
    }
    sum += (i * pro);
  }
  cout << sum;
  return 0;
}


Error: TLE

Fixed submission:

// C implementation of Naive method to count all
// divisors
#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long int ll;

using namespace std;

// function to count the divisors
ll countDivisors(int n) {
  ll 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;
}

/* Driver program to test above function */
int main() {
  IOS;
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += i * countDivisors(i);
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, n) for (ll i = 0; i < n; i++)
#define fb(i, n) for (ll i = n - 1; i >= 0; i--)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef pair<int, int> pii;
const int MAX = pow(10, 7) + 1;
long long is_composite[MAX] = {0};
// vector<ll> prime;
void sieve(void) {
  for (int i = 2; i < MAX; ++i) {
    // if (is_composite[i]==0) prime.push_back (i);
    for (int j = 2; i * j < MAX; ++j) {
      is_composite[i * j]++;
    }
  }
  for (int i = 1; i < MAX; i++) {
    is_composite[i] += 2;
    is_composite[i] = is_composite[i - 1] + (is_composite[i] * i);
  }
}
int main() {
  IOS;
  // int t; cin>>t;
  // ll M=pow(10,9)+7;
  int t = 1;
  while (t) {
    sieve();
    ll n;
    cin >> n;
    ll ans = is_composite[n] - 1;
    cout << ans;
    t--;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, n) for (ll i = 0; i < n; i++)
#define fb(i, n) for (ll i = n - 1; i >= 0; i--)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef pair<int, int> pii;
void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) {
  for (int i = 2; i <= n; i++)
    prime[i] = true;
  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;
  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }
  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (prime[p]) {
      a[j] = p;
      primesquare[p * p] = true;
      j++;
    }
  }
}
int countDivisors(int n) {
  if (n == 1)
    return 1;
  bool prime[n + 1], primesquare[n * n + 1];
  int a[n];
  SieveOfEratosthenes(n, prime, primesquare, a);
  int ans = 1;
  for (int i = 0;; i++) {
    if (a[i] * a[i] * a[i] > n)
      break;
    int cnt = 1;
    while (n % a[i] == 0) {
      n = n / a[i];
      cnt = cnt + 1;
    }
    ans = ans * cnt;
  }
  if (prime[n])
    ans = ans * 2;
  else if (primesquare[n])
    ans = ans * 3;
  else if (n != 1)
    ans = ans * 4;
  return ans;
}
int main() {
  IOS;
  // int t; cin>>t;
  // ll M=pow(10,9)+7;
  int t = 1;
  while (t) {
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
      ans = ans + i * countDivisors(i);
    }
    cout << ans;
    t--;
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define pb push_back
#define N 900000
#define ar array
typedef long long int ll;
using namespace std;
int main(void) {
  fast;
  // cout<<"**"<<endl;
  ll ans = 0, n, i, j;
  cin >> n;
  for (i = 2; i <= n; i++) {
    for (j = i; j <= n; j += i)
      ans += j;
  }
  ll a1 = n * (n + 1) / 2;
  ans += a1;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define pb push_back
#define N 900000
#define ar array
typedef long long int ll;
using namespace std;
int main(void) {
  fast;
  // cout<<"**"<<endl;
  ll n, ans = 0, i, j;
  cin >> n;
  vector<ll> a[n + 5];
  a[1].pb(1);
  for (i = 2; i <= n; i++) {
    if (a[i].size() == 0)
      for (j = i; j <= n; j += i)
        a[j].pb(i);
  }
  for (i = 2; i <= n; i++) {
    ll ls = 1, f = 0, temp;
    for (auto x : a[i]) {
      temp = i;
      f = 0;
      while (temp % x == 0) {
        f++;
        temp /= x;
      }
      ls *= (f + 1);
    }
    // cout<<ls<<endl;
    ll u = i * ls;
    ans += u;
  }
  cout << ans + 1;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll n;

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

  cin >> n;

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

  for (int i = 2; i <= n; i++) {
    res = res + (ll)i * (v[i] + 2);
  }
  cout << res;
  return 0;
}

Error: TLE

Fixed submission:

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

ll n;

ll pozitiveDivisors(ll x) {
  ll res;
  if (x == 1)
    res = 1;
  else
    res = 2;
  set<int> sol;
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      sol.insert(i);
      sol.insert(x / i);
    }
  }
  res += sol.size();
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n;

  ll sum = 0;

  for (int i = 1; i <= n; i++) {
    // cout<<pozitiveDivisors(i)<<" \\n";
    sum += i * pozitiveDivisors(i);
  }

  cout << sum;
  return 0;
}