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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)                                                            \\
  vector<ll> a(n);                                                             \\
  rep(i, n) { cin >> a[i]; }
#define repins(a, n)                                                           \\
  vector<string> a(n);                                                         \\
  rep(i, n) { cin >> a[i]; }
#define repind(a, n)                                                           \\
  vector<double> a(n);                                                         \\
  rep(i, n) { cin >> a[i]; }
#define in(a)                                                                  \\
  ll a;                                                                        \\
  cin >> a;
#define ins(a)                                                                 \\
  string a;                                                                    \\
  cin >> a;
#define ind(a)                                                                 \\
  double a;                                                                    \\
  cin >> a;
template <class T> inline void out(T a) { cout << a << endl; }
inline void out(double a) { printf("%.10f\\n", a); }
#define all(x) (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes out("Yes");
#define no out("No");

int main() {
  in(n);
  ll ans = 0;
  vector<ll> a(n + 1);

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

  rep2(i, 1, n + 1) { ans += i * a[i]; }

  out(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)                                                            \\
  vector<ll> a(n);                                                             \\
  rep(i, n) { cin >> a[i]; }
#define repins(a, n)                                                           \\
  vector<string> a(n);                                                         \\
  rep(i, n) { cin >> a[i]; }
#define repind(a, n)                                                           \\
  vector<double> a(n);                                                         \\
  rep(i, n) { cin >> a[i]; }
#define in(a)                                                                  \\
  ll a;                                                                        \\
  cin >> a;
#define ins(a)                                                                 \\
  string a;                                                                    \\
  cin >> a;
#define ind(a)                                                                 \\
  double a;                                                                    \\
  cin >> a;
template <class T> inline void out(T a) { cout << a << endl; }
inline void out(double a) { printf("%.10f\\n", a); }
#define all(x) (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes out("Yes");
#define no out("No");

vector<long long> enum_divisors(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  // 小さい順に並び替える
  sort(res.begin(), res.end());
  return res;
}

int main() {
  in(n);
  ll ans = 0;

  rep2(i, 1, n + 1) {
    auto c = enum_divisors(i).size();
    ans += i * c;
  }

  out(ans);
}