alexjercan/bugnet huggingface dataset:
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main(void) {
  ll N;
  cin >> N;

  ll ans = 0;

  for (ll j = 1; j <= N; j++) {
    ll Y = N / j;
    ans += (1 + Y) * Y * j / 2;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pe = pair<ll, ll>;

vector<pe> prime_factorize(ll num) {
  vector<pe> result;

  for (ll i = 2; i * i <= num; i++) {
    if (num % i != 0)
      continue;
    ll e = 0;

    while (num % i == 0) {
      e++;
      num /= i;
    }

    result.push_back({i, e});
  }

  if (num != 1)
    result.push_back({num, 1});
  return result;
}

bool isPrime(ll num) {
  if (num == 1)
    return false;
  for (ll i = 2; i * i <= num; i++) {
    if (num % i == 0)
      return false;
  }
  return false;
}

vector<ll> factorCounts;
vector<ll> isPrimeList;

ll prime_factor_count(ll num) {
  bool factorFound = false;
  if (factorCounts[num - 1] > 0) {
    return factorCounts[num - 1];
  }
  for (ll i = 2; i * i <= num; i++) {
    if (isPrimeList[i - 1]) {
      if (num % i == 0) {
        return 2 * factorCounts[num / i - 1];
      } else {
        continue;
      }
    } else {
      continue;
    }
  }
  vector<pe> result = prime_factorize(num);
  ll count = 1;
  for (auto res : result) {
    count *= (res.second + 1);
  }
  factorCounts[num - 1] = count;
  return count;
}

ll prime_factor_count2(ll num) {
  bool factorFound = false;
  for (ll i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      return factorCounts[i - 1] * factorCounts[num / i - 1];
    } else {
      continue;
    }
    continue;
  }

  vector<pe> result = prime_factorize(num);
  ll count = 1;
  for (auto res : result) {
    count *= (res.second + 1);
  }
  factorCounts[num - 1] = count;
  return count;
}

int main(void) {
  ll N;
  cin >> N;

  factorCounts.resize(N);
  factorCounts[0] = 1;
  factorCounts[1] = 2;
  factorCounts[2] = 2;
  isPrimeList.resize(N);
  ll result = 1;

  for (ll i = 2; i < N + 1; i++) {
    ll count = prime_factor_count(i);
    result += i * count;
  }

  cout << result << endl;

  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll f(ll n) { return n * (n + 1) / 2; }

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  rep(i, n) {
    ll r = n / i;
    ans += i * f(r);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  rep(i, n) {
    rep(j, n) {
      if (!(i % j))
        ans += i;
    }
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<ll> divisor(ll n) {
  vector<ll> vec;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      vec.push_back(i);
      if (i * i != n)
        vec.push_back(n / i);
    }
  }
  // sort(vec.begin(), vec.end());
  return vec;
}

int main(void) {
  int n;
  cin >> n;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll y = n / i;
    ans += y * (y + 1) * i / 2;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

vector<ll> divisor(ll n) {
  vector<ll> vec;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      vec.push_back(i);
      if (i * i != n)
        vec.push_back(n / i);
    }
  }
  // sort(vec.begin(), vec.end());
  return vec;
}

int main(void) {
  int n;
  cin >> n;

  ll ans = 1;
  map<int, int> mp;
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      mp[j]++;
    }
  }
  for (ll i = 2; i <= n; i++) {
    ans += i * (mp[i] + 1);
  }
  // for(auto p: mp) cout << p.first << " " << p.second << endl;
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1000000007;
ll cnt = 0, ans = 0;
bool graph[8][8];

int main() {
  ll k;
  cin >> k;

  vector<int> a(k + 10);
  for (int i = 0; i <= k; i++) {
    a[i] = 0;
  }

  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= k; j += i) {
      a[j]++;
    }
  }

  for (ll i = 1; i <= k; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1000000007;
ll cnt = 0, ans = 0;
bool graph[8][8];

int main() {
  ll k;
  cin >> k;

  ll a[k + 10];
  for (int i = 0; i <= k; i++) {
    a[i] = 0;
  }

  for (int i = 1; i <= k; i++) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        a[i] += 2;
      }
      if (j * j == i)
        a[i]--;
    }
  }

  for (int i = 1; i <= k; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;

// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }

  return res;
}

// 素因数分解 O(√n)
map<int, int> prime_factor(int n) {
  map<int, int> res;

  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
    res[n] = 1;

  return res;
}

// 約数の個数を列挙 O(N)
void divisor_count(vector<ll> &dp, ll n) {
  dp[0] = 0;
  dp[1] = 1;

  for (ll i = 2; i < n / 2 + 1; i++) {
    ll j = 2;
    while (i * j <= n) {
      dp[i * j]++;
      j++;
    }
  }
}

int main() {
  ll N;
  cin >> N;

  vector<ll> dp(N + 1, 2);
  ll ans = 0;

  divisor_count(dp, N);
  rep(i, N + 1) { ans += i * dp[i]; }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;

// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }

  return res;
}

// 素因数分解 O(√n)
map<int, int> prime_factor(int n) {
  map<int, int> res;

  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
    res[n] = 1;

  return res;
}

void f(vector<ll> &dp, ll n) {
  if (dp[n] != 0)
    return;

  vector<ll> divs = divisor(n);
  dp[n] = divs.size() * n;

  repv(divs) { f(dp, *it); }
  return;
}

int main() {
  ll N;
  cin >> N;

  vector<ll> dp(N + 1, 0);
  ll ans = 0;

  for (ll i = N; i > 0; i--) {
    if (dp[i] != 0)
      continue;
    f(dp, i);
  }

  for (ll i = 0; i <= N; i++) {
    ans += dp[i];
  }

  cout << ans << endl;

  // repv(dp) { cout << *it << " "; }
  // cout << endl;
  // cout << ans << endl;

  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
#define ll unsigned long long int

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<int> sum(n + 1);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; i * j <= n; j++) {
      sum[i * j]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += sum[i] * i;
  }
  cout << ans << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
#define ll unsigned long long int
#define MAX 10000000
vector<ll> s(MAX);
void seive(int n) {
  s[0] = 0, s[1] = 1;
  for (int i = 2; i <= n; i++) {
    s[i] = i;
  }
  for (int i = 4; i <= n; i += 2)
    s[i] = 2;
  for (int i = 2; i * i <= n; i++) {
    if (s[i] == i) {
      for (int j = i * i; j <= n; j += i) {
        if (s[j] == j)
          s[j] = i;
      }
    }
  }
}

int nooffactors(int n) {
  if (n == 1)
    return 1;
  ll ans = 1;
  int dup = s[n];
  int c = 1;
  int j = n / s[n];
  while (j != 1) {
    if (s[j] == dup)
      c++;
    else {
      dup = s[j];
      ans = ans + (1 + c);
      c = 1;
    }
    j = j / s[j];
  }
  ans *= (c + 1);
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector<ll> v(n + 1);
  v[0] = 0, v[1] = 1, v[2] = 5, v[3] = 11;
  for (int i = 3; i <= n; i++) {
    if (s[i] == i)
      v[i] = 2 * i + v[i - 1];
    else
      v[i] = nooffactors(i) * i + v[i - 1];
  }
  cout << v[n] << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll a = n / i;
    ll g = a * (a + 1) / 2;
    ans += i * g;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;

bool isPrime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

ll enum_div(ll N) {
  ll sum = 0;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      sum++;
      if (i != N / i) {
        sum++;
      }
    }
  }
  return sum;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll r = 1; r <= n; r++) {
    if (isPrime(r)) {
      ans += 2 * r;
    } else {
      ans += r * enum_div(r);
    }
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

int main() {
  ll n;
  cin >> n;
  ll ch[10000100];
  for (ll i = 1; i <= n; i++) {
    ch[i] = 1;
  }
  for (ll i = 2; i <= n; i++) {
    ll now = 1;
    while ((now)*i <= n) {
      ch[now * i]++;
      //	cout <<now*i<<endl;
      now++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * ch[i];
  }
  cout << ans;
  // your code goes here
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}
int main() {
  ll n;
  cin >> n;
  ll N = n;
  vector<ll> so;
  for (const auto &x : Eratosthenes(N)) {
    so.push_back(x);
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll cnt = 1;
    ll now = i;
    for (ll j = 0; j < so.size(); j++) {
      ll cnt2 = 1;
      while (now % so[j] == 0) {
        now /= so[j];
        cnt2++;
      }
      cnt *= cnt2;
      if (now == 1) {
        break;
      }
    }
    ans += i * cnt;
  }
  cout << ans;
  // your code goes here
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define UN unsigned
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define pb push_back
//~ #define x first
//~ #define y second
const int N = 1e7 + 1;

int main(void) {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);

  int n = 0;
  cin >> n;
  vector<int> d(N, 2);
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans += 1LL * d[i] * i;
    for (int j = 2; j * i <= n; j++) {
      d[i * j]++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define UN unsigned
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define pb push_back
//~ #define x first
//~ #define y second
// const int N = 1e6 + 5;

int main(void) {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);

  int n = 0;
  cin >> n;
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    int cnt = 2;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        cnt++;
        if (i / j != j)
          cnt++;
      }
    }

    ans += 1LL * cnt * i;
  }

  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  int64_t sum = 0;

  for (int i = 1; i <= N; i++) {
    int64_t num = N / i;
    sum += i * (num + 1) * num / 2;
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int64_t ans = 0;
  vector<vector<int>> N_div(N + 1, vector<int>(N + 1));

  for (int n = 1; n <= N; n++) {
    if (n == 1) {
      ans += 1 * 1;
      N_div.at(1).at(1) = 1;
      continue;
    }
    if (n == 2) {
      ans += 2 * 2;
      N_div.at(2).at(2) = 1;
      continue;
    }
    if (n == 3) {
      ans += 3 * 2;
      N_div.at(3).at(3) = 1;
      continue;
    }

    int64_t count = 1;
    int num = n;

    bool flag = false;
    for (int i = 2; i * i <= n; i++) {
      if (num % i == 0) {
        num /= i;
        N_div.at(n) = N_div.at(num);
        N_div.at(n).at(i)++;
        flag = true;
        break;
      }
    }
    if (!flag) {
      N_div.at(n).at(num)++;
    }

    for (int i = 2; i <= n; i++) {
      count *= N_div.at(n).at(i) + 1;
    }
    ans += (n * count);
  }

  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> PII;
int divisors[10000001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      divisors[j]++;
  // cout<<divisors[100]<<"\\n";
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    long long int t1 = divisors[i], t2 = i, t3 = t2 * t1;
    sum += t3;
  }
  printf("%lld", sum);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<int> divisors[10000001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      divisors[j].push_back(i);
  long long int sum = 0;
  for (int i = 1; i <= n; i++)
    sum = sum + i * divisors[i].size();
  printf("%lld", sum);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long int n;
  cin >> n;
  long long int ans = 0;
  vector<long long int> v(n + 1, 0);
  for (long int i = 1; i <= n; i++) {
    for (long int j = 0; j <= n; j += i) {
      v[j]++;
    }
  }
  for (long int i = 1; i <= n; i++) {
    ans += i * v[i];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
int main() {

  long int n;
  cin >> n;
  long long int ans = 0;
  for (long int i = 1; i <= n; i++) {
    for (long int j = 1; j <= n; j++) {
      if (i % j == 0)
        ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      a += j;
    }
  }
  cout << a;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (i % j == 0)
        a += i;
    }
  }
  cout << a;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

ll g(ll n) { return n * (n + 1) / 2; }

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * g(n / i);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> y(n + 1);
  for (int i = 1; i <= n; i++) {
    if (n == 1) {
      y[i]++;
      break;
    }
    map<int, int> s;
    int tmp = i;
    for (int j = 2; j * j <= i; j++) {
      while (tmp % j == 0) {
        s[j]++;
        tmp /= j;
      }
    }
    if (tmp > 1)
      s[tmp]++;
    int sum = 1;
    for (auto v : s) {
      sum *= v.second + 1;
    }
    y[i] = sum;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * y[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

namespace ABC172 {

class D {
public:
  D() = default;
  ~D() = default;

  void Run() {
    int N = {};
    std::cin >> N;

    long long sum = 0;

    for (long long i = 1; i <= N; ++i) {
      long long max_k = N / i;
      sum += (i * (max_k + 1) * (max_k)) / 2;
    }

    std::cout << sum << std::endl;
  }
};
} // namespace ABC172
int main() {

  ABC172::D prob;
  prob.Run();

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

namespace ABC172 {
static long long f[10000000 + 1] = {};

class D {
public:
  D() = default;
  ~D() = default;

  std::vector<long long> getDivisorList(int n) {
    std::vector<long long> ret = {};
    for (int i = 1; i * i <= n; ++i) {
      if (n % i == 0) {
        ret.push_back(i);
        long long add = n / i;
        if (add != i)
          ret.push_back(add);
      }
    }
    return ret;
  }

  std::vector<int> plist = {1,  2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31,
                            37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79};
  void Run() {
    int N = {};
    std::cin >> N;

    long long sum = 0;
    for (int i = 1; i <= N; ++i) {
      int div_num = 1;
      if (f[i] == 0) {
        // 新規登録
        auto divisors = getDivisorList(i);
        int num = divisors.size();
        for (auto p : plist) {
          long long index = i * p;
          if (i * p > 10000001)
            break;
          if (i < p) {
            f[i * p] = num * 2; // 約数すべてにpをかけた分だけある
          } else {
            int yaku_num = num;
            for (auto d : divisors) {
              bool already_exists = false;
              auto r = d * p;
              for (auto d2 : divisors) {
                already_exists |= d2 == r;
              }
              if (!already_exists)
                yaku_num++;
            }
            f[i * p] = yaku_num;
          }
        }
      }
      div_num = f[i];

      sum += i * div_num;
    }

    std::cout << sum << std::endl;
  }
};
} // namespace ABC172

int main() {

  ABC172::D prob;
  prob.Run();

  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> M(N + 1);
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= N; j++) {
      if (i * j > N)
        break;
      M.at(i * j)++;
    }
  }
  long long sum = 0;
  for (long long i = 1; i <= N; i++) {
    sum += M.at(i) * i;
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int64_t N, num, div_num = 1, div_sum = 0, n;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    div_num = 1;
    n = i;
    for (int j = 2; j <= sqrt(n); j++) {
      num = 1;
      while (n % j == 0) {
        n /= j;
        num++;
      }
      div_num *= num;
      if (n == 1) {
        break;
      }
    }
    if (n != 1) {
      div_num *= 2;
    }
    div_sum += i * div_num;
  }
  cout << div_sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, k, i, ans = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    k = n / i;
    ans += k * (k + 1) / 2 * i;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, i, j, k, l, m, ans = 1;
  cin >> n;
  vector<int64_t> p, a(n + 1);
  a.at(1) = 1;
  for (i = 2; i <= n; i++) {
    k = i;
    l = 0;
    m = 1;
    for (j = 0; j < p.size() && p.at(j) * p.at(j) <= i; j++) {
      while (k % p.at(j) == 0) {
        l++;
        k /= p.at(j);
        m *= p.at(j);
      }
      if (l > 0) {
        a.at(i) = m * (l + 1) * a.at(k);
        ans += a.at(i);
        break;
      }
    }
    if (k == i) {
      a.at(i) = i * 2;
      ans += a.at(i);
      if (i * i <= n)
        p.push_back(i);
    }
  }
  cout << ans << endl;
}