Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

#define db1(x) cout << #x << " : " << x << endl;
#define db2(x, y) cout << #x << " : " << x << "\\t" << #y << " : " << y << endl;
#define db3(x, y, z)                                                           \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\t" << #z << " : "  \\
       << z << endl;

typedef long long int ll;
typedef long double ld;

const int N = 2e5 + 5;
const int inf = INT_MAX;
const int MOD = 1e9 + 7;

void solve() {
  ll n;
  cin >> n;
  vector<ll> a(n + 15, 1);
  a[1] = 1;
  ll i, j;
  for (i = 2; i <= n; i++) {
    for (j = 1; j * 1LL * i <= n; j++) {
      a[i * 1LL * j]++;
    }
  }
  ll ans = 0;
  for (i = 1; i <= n; i++) {
    ans += i * 1LL * a[i];
  }
  cout << ans << endl;
}

int32_t main() {
  IOS;
  // freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Error: TLE

Fixed submission:

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

#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

#define db1(x) cout << #x << " : " << x << endl;
#define db2(x, y) cout << #x << " : " << x << "\\t" << #y << " : " << y << endl;
#define db3(x, y, z)                                                           \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\t" << #z << " : "  \\
       << z << endl;

typedef long long int ll;
typedef long double ld;

const int N = 2e5 + 5;
const int inf = INT_MAX;
const int MOD = 1e9 + 7;

#define int ll

void solve() {
  int n;
  cin >> n;
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (int p = 2; p * p < n; p++)
    if (hash[p] == true)
      for (int i = p * 2; i < n; i += p)
        hash[i] = false;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int nn = i;
    int total = 1;
    for (int p = 2; p <= nn; p++) {
      if (hash[p]) {
        int count = 0;
        if (nn % p == 0) {
          while (nn % p == 0) {
            nn = nn / p;
            count++;
          }
          total = total * 1LL * (count + 1);
        }
      }
    }
    ans += i * 1LL * total;
  }
  cout << ans;
}

int32_t main() {
  IOS;
  // freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/