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

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto &a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename Num> constexpr Num mypow(Num a, long long b) {
  if (b == 0)
    return 1;
  if (a == 0)
    return 0;
  Num x = 1;
  while (b > 0) {
    if (b & 1)
      x *= a;
    a *= a;
    b >>= 1;
  }
  return x;
}

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

// lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
// mint,dijkstra,gyakugen
ll n;

void input() {
  cin >> n;
  return;
}

void solve() {
  ll res = 0;
  rep(i, n) {
    ll x = i + 1;
    ll y = n / x;
    res += y * (x + y * x) / 2;
  }
  cout << res << "\\n";
  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  input();
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto &a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename Num> constexpr Num mypow(Num a, long long b) {
  if (b == 0)
    return 1;
  if (a == 0)
    return 0;
  Num x = 1;
  while (b > 0) {
    if (b & 1)
      x *= a;
    a *= a;
    b >>= 1;
  }
  return x;
}

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

// lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
// mint,dijkstra,gyakugen
map<ll, map<ll, ll>> m;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  bool c = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0 && n / i != 1) {
      ret = m[n / i];
      c = false;
      ret[i]++;
      break;
    }
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (c)
    ret[n] = 1;
  return m[n] = ret;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  ll res = 1;
  rep(i, n - 1) {
    ll k = i + 2;
    map<ll, ll> m2 = prime_factor(k);
    ll x = 1;
    rbf(p, m2) { x *= p.Se + 1; }
    res += x * k;
  }
  cout << res << endl;
}