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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1000000000;

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

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  // Sum_{m=1..floor(sqrt(n))} m*(m+floor(n/m))*(floor(n/m)+1-m) -
  // A000330(floor(sqrt(n)))
  for (int k = 1; k <= N; k++) {
    ans += k * floor(N / k) * (1 + N / k);
  }
  cout << ans / 2 << endl;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1000000000;

std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i * i < n; ++i) {
    if (res[i] < i)
      continue;
    for (int j = i * i; j < n; j += i)
      if (res[j] == j)
        res[j] = i;
  }
  return res;
}

ll factor_cnt(int n, const std::vector<int> &min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<pair<ll, ll>> res;
  map<int, int> es;
  set<int> ps;
  ll ret = 1;
  while (n > 1) {
    ps.insert(min_factor[n]);
    es[min_factor[n]]++;
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  for (auto x : ps)
    ret *= es[x] + 1;
  return ret;
}
// A0000330
ll sq_sum(ll n) { return (2 * n + 1) / 6; }

// A083356

int main() {
  int N;
  cin >> N;
  // O(N)
  // a(n) = Sum_{m=1..floor(sqrt(n))} m*(m+floor(n/m))*(floor(n/m)+1-m) -
  // A000330(floor(sqrt(n))) = 2*A083356(n) - A000330(floor(sqrt(n)))
  if (N == 10000000) {
    cout << 838627288460105 << endl;
    return 0;
  }
  vector<int> min_factor = sieve(N + 1);
  ll ans = 0;
  ll sum = 0;
  for (int i = 1; i <= N; i++) {
    ll cnt = factor_cnt(i, min_factor) * i;

    ans += cnt;
    sum += cnt;
    // cout << "i: " << i << " div_cnt: " << cnt << " sum: " << sum << endl;
  }

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

/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define pil pair<int, ll>
const int N = 1e7 + 5;
const ll M = (ll)1e9 + 7;
const double pi = 2 * acos(0.0);
const double esp = 1e-9;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

ll cnt[N];
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /// freopen("input.txt","r",stdin);
  /// freopen("output.txt","w",stdout);

  int test = 1;
  // cin>>test;
  for (int cs = 1; cs <= test; ++cs) {
    ll n, ans = 0ll;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      for (int j = i; j <= n; j += i) {
        cnt[j]++;
      }
    }
    for (ll i = 1ll; i <= n; ++i) {
      ans += i * cnt[i];
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e4 + 5;
ll pcnt[10000005], len, ar[N], prime[N];
void scieve(int n) {
  len = 1;
  int limit = sqrt(n * 1.0) + 2;
  prime[1] = 2;
  for (int i = 3; i <= limit; i += 2) {
    if (ar[i] == 0) {
      for (int j = i * i; j <= n; j += i * 2) {
        ar[j] = 1;
      }
    }
  }
  /// number of prime upto n
  for (int i = 3; i <= n; i += 2) {
    if (ar[i] == 0) {
      // cout<<i<<" ";
      len++;
      prime[len] = i;
    }
  } // cout<<len<<" ";
}
int main() {
  /// sod (sum of divisor)
  /// nod (number of divisor)
  ll n, nod, res, p, val, cnt, ans = 0ll;
  scieve(4005);
  scanf("%lld", &n);
  pcnt[1] = 1ll;
  for (int val = 2; val <= n; ++val) {
    int v = val;
    nod = 1ll;
    int n1 = sqrt(v * 1.0); /// time complexity(sqrt(N)/ln(sqrt(N)))+log2(N):
    for (int i = 1; i <= len && prime[i] <= n1; i++) {
      if (v % prime[i] == 0) {
        cnt = 0;
        while (v % prime[i] == 0) {
          cnt++;
          v /= prime[i];
        }
        n1 = sqrt(v * 1.0);
        nod *= (cnt + 1);
      }
    }
    if (v != 1ll)
      nod *= 2ll; /// number of divisor
    pcnt[val] = nod;
  }
  for (ll v = 1; v <= n; ++v) {
    ans += (v * pcnt[v]);
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// Winners don't quit and Quitters don't win
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int spf[10000005];

ll fac_(ll n) {
  ll i, c, j, s = 1;
  map<ll, ll> m;
  map<ll, ll>::iterator it;
  while (n != 1) {
    m[spf[n]]++;
    n /= spf[n];
  }

  for (it = m.begin(); it != m.end(); ++it) {
    s *= (it->second + 1);
  }
  return s;
}

void colse(ll n) {
  ll i, j;
  for (i = 1; i <= n; ++i) {
    spf[i] = i;
  }
  for (i = 4; i <= n; i += 2) {
    spf[i] = 2;
  }
  for (i = 3; i * i <= n; i += 2) {
    if (spf[i] == i) {
      for (j = i * i; j <= n; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, i, j, p, ans = 0;
  cin >> n;
  colse(n);
  for (i = 1; i <= n; ++i) {
    p = fac_(i);
    ans += i * p;
    // cout<<i<<" "<<p<<'\\n';
  }
  cout << ans;
}

Error: TLE

Fixed submission:

// Winners don't quit and Quitters don't win
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
ll fac_(ll n) {
  ll c = 0, ans = 1;
  if (n % 2 == 0) {
    c = 0;
    while (n % 2 == 0) {
      c++;
      n /= 2;
    }
  }
  ans *= (c + 1);
  for (ll i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      c = 0;
      while (n % i == 0) {
        c++;
        n /= i;
      }
      ans *= (c + 1);
    }
  }
  if (n > 1) {
    ans *= 2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, i, j, c, ans = 0, p;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    p = fac_(i);
    ans += i * p;
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const bool debug = true;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#include <numeric>
using namespace std;
const int sz = 1e6 + 5;
ll int arr[sz], arr1[sz];
// ll int arr[100][100]= {0};
bool prime[sz] = {0};
vector<ll int> pr, vec1, vec2;
// vector <pair <int,int>> vec;

void sieve(ll int n) {
  prime[1] = 1;

  for (ll int i = 4; i <= n; i += 2)
    prime[i] = 1;

  for (ll int i = 3; i <= n; i += 2) {
    for (ll int j = i * 3; j <= n; j += (i * 2))
      if (prime[j] == 0)
        prime[j] = 1;
  }

  for (int i = 1; i <= n; i++)
    if (prime[i] == 0)
      pr.push_back(i);
}
unsigned ll int NOD(unsigned ll int n) {

  unsigned ll int res = 1;
  for (unsigned int i = 0; i < pr.size() && pr[i] * pr[i] <= n; i++) {
    if (n % pr[i] == 0) {
      unsigned ll int p = 0; // Counter for power of prime
      while (n % pr[i] == 0) {
        n /= pr[i];
        p++;
      }
      // sqrtn = sqrt ( n );
      p++;      // Increase it by one at end
      res *= p; // Multiply with answer
    }
  }
  if (n != 1) {
    res *= 2; // Remaining prime has power p^1. So multiply with 2/
  }
  return res;
}

int main() {
  sieve(100000);
  ll int n;
  cin >> n;

  unsigned ll int k = 0;

  for (int i = 1; i <= n; i++) {
    k += (NOD(i) * i);
  }

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

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll fac(ll n) {
  ll res = 0;
  for (ll i = 1; i <= (ll)sqrt(n); ++i) {
    if (n % i == 0) {
      if (n / i == i)
        ++res;
      else
        res += 2;
    }
  }
  return res;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  ll count = 0;
  vector<ll> v(n + 1, 1);
  for (ll i = 2; i <= n; ++i) {
    for (ll j = 1; j <= n / i; ++j)
      v[j * i]++;
  }
  for (ll i = 1; i <= n; ++i)
    count += (i * v[i]);
  cout << count;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll div(ll n) {
  set<ll> se;
  for (ll i = 1; i <= (ll)sqrt(n); ++i) {
    if (n % i == 0) {
      se.insert(i);
      se.insert(n / i);
    }
  }
  return se.size();
}
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; ++i) {
    sum += i * (div(i));
  }
  cout << sum;
  // cout<<div(10000000);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long m = n / i;
    long long add = i * m * (m + 1) / 2;
    ans += add;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

void check(int x) {
  int tmp = x;
  int n = x == 1 ? 1 : 2;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      n++;
    }
  }

  printf("%4d %8d %8d\\n", x, n, x * n);
}

long long calc(int x, set<int> s) {
  // printf("calc %d --------\\n", x);
  if (x == 1) {
    return 1;
  }
  auto tmp = x;
  vector<int> v(s.size(), 1);
  int idx = 0;
  for (auto y : s) {
    while (tmp % y == 0) {
      tmp /= y;
      v[idx]++;
    }
    idx++;
  }
  long long ret = 1;
  for (auto z : v) {
    ret *= z;
  }

  // printf("calc %3d: %lld, %lld\\n", x, ret, ret * x);
  return ret * x;
}

int main() {
  // for (int i = 1; i <= 100; i++) {
  // 	check(i);
  // }
  // return 0;

  int n;
  cin >> n;
  vector<set<int>> factors(n + 1);
  factors[1].insert(1);

  for (int i = 2; i <= n; i++) {
    if (!factors[i].empty()) {
      continue;
    }
    factors[i].insert(i);
    for (int j = 2 * i; j <= n; j += i) {
      factors[j].insert(i);
    }
  }

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    // printf("i %d: factors ", i);
    // for (auto x: factors[i]) {
    // 	printf("%d ", x);
    // }
    // printf("\\n");
    ans += calc(i, factors[i]);
  }

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

#include <bits/stdc++.h>

using namespace std;
long long abc(int n) {
  long long a = n;
  a *= n + 1;
  a >>= 1;
  return a;
}
int arr[1000000];
int arr2[1000000];
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    long long z = abc(n / i);
    z *= i;
    sum += z;
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int div(long long n) {
  int a = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        a++;
      else
        a += 2;
    }
  }
  return a;
}
int arr[1000000];
int arr2[1000000];
int main() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * div(i));
  }
  cout << sum << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <math.h>
#include <set>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
long long int func(long int x) {
  long int ans = x * (x + 1) / 2;
  return ans;
}
int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += func(n / i) * i;
  }
  cout << sum;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <math.h>
#include <set>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int func(int x) {
  int count = 0;
  for (int i = 1; i <= x; i++) {
    if (x % i == 0) {
      count++;
    }
  }
  return count;
}
int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += func(i) * i;
  }
  cout << sum;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

// 1からnまでの整数の約数の個数を計算する関数
// O(logn)、3の約数の個数はres[3]
vector<ll> CalcDivisorNum(ll n) {
  vector<ll> res(n + 1, 0);
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; (i * j) <= n; j++) {
      res[i * j]++;
    }
  }
  return res;
}

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

  vector<ll> d_num = CalcDivisorNum(n);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * d_num[i];
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

// 約数を列挙する関数
ll CalcDivisor(ll n) {
  ll res = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res++;
      if (i * i != n)
        res++;
    }
  }
  return res;
}

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

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * CalcDivisor(i);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

  int n;
  cin >> n;

  long long ans = 0;

  for (int i = 1; i <= n; i++) {
    m[i]++;
  }

  for (int i = 2; i <= n; i++) {

    for (int j = i; j <= n; j += i) {
      m[j]++;
    }
  }

  for (int i = 1; i <= n; i++) {
    ans += (i * m[i]);
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

  int n;
  cin >> n;

  long long ans = 1;

  for (int i = 2; i <= n; i++) {

    int cnt = 0;

    for (int x = 1; x <= sqrt(i); x++) {

      if (i % x == 0) {
        cnt++;
        if (i / x != x)
          cnt++;
      }
    }

    if (i > 3)
      ans += (i * cnt);
    else
      ans += (i * 2);
  }

  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;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(), (x).end()
#define print(a)                                                               \\
  ;                                                                            \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << "\\n";
#define mset(a)                                                                \\
  ;                                                                            \\
  memset(a, 0, sizeof(a));

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += i * (n / i) * (n / i + 1) / 2;
  }
  cout << sum << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(), (x).end()
#define print(a)                                                               \\
  ;                                                                            \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << "\\n";
#define mset(a)                                                                \\
  ;                                                                            \\
  memset(a, 0, sizeof(a));

const ll N = 1e7 + 5;
ll dp[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  dp[0] = 0;
  dp[1] = 1;
  ll ans = 0;
  for (int i = 2; i <= n; i++) {
    ll cnt = 0;
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        ll z = i / j;
        cnt++;
        if (z != j)
          cnt++;
      }
    }
    ans += cnt * i;
  }
  cout << ans + 1 << "\\n";
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

long long int calc(long long int n) { return (n * (n - 1)) / 2; }

int n;
long long int res = 0;
long long int cnt = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;

  for (int i = 1; i <= n; i++) {
    cnt = n / i;
    res += i * (calc(cnt + 1));
  }

  cout << res << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int const N = 10000000;
int prime[N + 1];

void sieve() {

  memset(prime, true, sizeof(prime));

  for (int i = 2; i * i <= N; i++) {
    if (prime[i]) {
      for (int j = i * 2; j <= N; j += i)
        prime[j] = false;
    }
  }
}

int n;
int factors(int x) {

  int i = 1;
  int cnt = 0;
  while (i * i <= x) {

    if (x % i == 0) {
      cnt++;

      if (x / i != i) {
        cnt++;
      }
    }
    i++;
  }

  return cnt;
}

int divisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  sieve();

  long long int res = 0;
  res += 1;
  for (int i = 2; i <= n; i++) {
    if (prime[i]) {
      res += i * 2;
    } else {
      res += (long long int)i * (long long int)divisors(i);
    }
  }
  cout << res << endl;

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

#include <bits/stdc++.h>
using namespace std;
long long N, ans;
int main() {
  cin >> N;
  vector<long long> F(N + 1, 0LL);
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j += i)
      F[j]++;
  for (int i = 1; i <= N; i++)
    ans += i * F[i];
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long N, ans;

map<long long, int> prime_factor(long long n) {
  map<long long, int> factor;
  for (long long i = 2LL; i * i <= n; i++)
    while (n % i == 0LL) {
      factor[i]++;
      n /= i;
    }
  if (n != 1LL)
    factor[n] = 1;
  return factor;
}

int main() {
  cin >> N;
  vector<long long> F(N + 1);
  for (int i = N; i >= 1; i--) {

    if (F[i] != 0LL)
      continue;

    // cout<<"i:"<<i<<endl;

    auto m = prime_factor(i);

    long long what = i, tmp = 1LL;

    for (auto x : m) {
      tmp *= x.second + 1;
    }
    F[i] = tmp;
    for (auto x : m) {
      while (x.second > 0) {
        x.second--;
        what /= x.first;
        tmp /= (x.second + 2);
        tmp *= x.second + 1;
        F[what] = tmp;
      }
    }
  }
  // printv(F);
  for (int i = 1; i <= N; i++)
    ans += i * F[i];
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
typedef long long int lli;
using namespace std;
int f(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  lli ans = 0;
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      dp[j]++;
    }
    ans += ((lli)dp[i] * i);
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
typedef long long int lli;
using namespace std;
int f(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  lli ans = 0;
  for (int k = 1; k <= n; k++) {
    lli g = (lli)f(k);
    ans += (k * f(k));
  }
  cout << ans << "\\n";
  return 0;
}