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

#include <bits/stdc++.h>
using namespace std;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  for (int i = 0; i < t; i++)
#define ll long long int
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define um(a, b) unordered_map<a, b>
#define vv(a) vector<a>
#define pp(a, b) pair<a, b>
ll power(ll a, ll b, ll mod) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b = b / 2;
  }
  return ans;
}
#define imax 10000005
ll arr[imax];
void pre() {
  for (ll i = 1; i < imax; i++) {
    arr[i] = i;
  }

  for (ll i = 2; i * i < imax; i++) {
    if (arr[i] == i) {
      for (int j = i * i; j < imax; j += i) {
        arr[j] = i;
      }
    }
  }
  return;
}
ll find(ll num) {
  map<ll, ll> mymap;
  while (num > 1) {
    mymap[arr[num]]++;
    num = num / arr[num];
  }
  ll ans = 1;
  for (auto k : mymap) {
    ans = ans * (k.second + 1);
  }
  return ans;
}
int main() {
  FIO pre();
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll s = find(i);
    ans += (i * s);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  for (int i = 0; i < t; i++)
#define ll long long int
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define um(a, b) unordered_map<a, b>
#define vv(a) vector<a>
#define pp(a, b) pair<a, b>
ll power(ll a, ll b, ll mod) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b = b / 2;
  }
  return ans;
}
#define imax 10000005
ll arr[imax];
void pre() {
  for (ll i = 1; i < imax; i++) {
    arr[i] = i;
  }
  for (ll i = 2; i < imax; i += 2) {
    arr[i] = 2;
  }
  for (ll i = 3; i * i < imax; i++) {
    if (arr[i] == i) {
      for (int j = i * i; j < imax; j += i) {
        arr[j] = i;
      }
    }
  }
  return;
}
ll find(ll num) {
  unordered_map<ll, ll> mymap;
  while (num > 1) {
    mymap[arr[num]]++;
    num = num / arr[num];
  }
  ll ans = 1;
  for (auto k : mymap) {
    ans = ans * (k.second + 1);
  }
  return ans;
}
int main() {
  FIO pre();
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll s = find(i);
    ans += (i * s);
  }
  cout << ans << endl;
}