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

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout                                                                   \\
  if (false)                                                                   \\
  cout
#define debug() if (false)
#define dvout(v)                                                               \\
  if (false)                                                                   \\
  vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)                                                                \\
  for (auto &i : v) {                                                          \\
    cout << i << " ";                                                          \\
  }                                                                            \\
  cout << "\\n"; // 配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vin(v)                                                                 \\
  for (auto &i : v)                                                            \\
    cin >> i; // 配列入力

#define mod (int)(1e9 + 7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\\n"
#define _n2 "\\n\\n"
#define _t "\\t"

void Main() {
  int N;
  cin >> N;
  vec(v, N + 1);
  for (int k = 1; k <= N; k++) {
    for (int i = k; i <= N; i += k) {
      v[i]++;
    }
  }

  ull ans = 0;
  for (int k = 1; k <= N; k++) {
    ans += (ull)k * v[k];
    // dout<<k<<':'<<v[k]<<_n;
  }

  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: TLE

Fixed submission:

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout                                                                   \\
  if (false)                                                                   \\
  cout
#define debug() if (false)
#define dvout(v)                                                               \\
  if (false)                                                                   \\
  vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)                                                                \\
  for (auto &i : v) {                                                          \\
    cout << i << " ";                                                          \\
  }                                                                            \\
  cout << "\\n"; // 配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vin(v)                                                                 \\
  for (auto &i : v)                                                            \\
    cin >> i; // 配列入力

#define mod (int)(1e9 + 7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\\n"
#define _n2 "\\n\\n"
#define _t "\\t"

void Main() {
  int N;
  cin >> N;

  ull ans = 0;
  for (int K = 1; K <= N; K++) {
    ull cnt = 0;
    for (int i = 1; i * i <= K; i++) {
      if (K % i == 0) {
        if (i * i == K)
          cnt++;
        else
          cnt += 2;
      }
    }
    //	dout<<"F("<<K<<")="<<cnt<<_n;
    ans += K * cnt;
  }

  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}