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

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)(1e7 + 1)
#define mod (ll)(1e9 + 7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define pi pair<ll, ll>
#define vvpi vector<vector<pi>>
#define vpi vector<pi>
#define vppi vector<pair<ll, pi>>
#define vs vector<string>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v, n) v.clear(), v.resize(n + 1, 0)
#define print(v)                                                               \\
  for (ll it = 0; it < v.size(); it++)                                         \\
    cout << v[it] << " ";                                                      \\
  cout << endl
#define printp(v)                                                              \\
  for (ll it = 0; it < v.size(); it++)                                         \\
  cout << v[it].first << " " << v[it].second << endl
using namespace std;
int main() {
  int n;
  cin >> n;
  ll s = 0;
  vector<ll> d(n + 1, 0);
  int i, j;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i)
      d[j]++;
  }
  for (i = 1; i <= n; i++) {
    s += (i * d[i]);
  }
  cout << s << endl;
}


Error: TLE

Fixed submission:

// i hate _____
#include <bits/stdc++.h>

#define ll long long int
#define ld long double
#define pb push_back
#define mk make_pair
#define ii pair<int, int>

using namespace std;
double pi = 2 * acos(0.0);

/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  for (const auto &x : v)
    os << " " << x;
  return os << '}';
}

void solve() {
  ll n;
  scanf("%lld", &n);
  ll ans = 0, d, sq;
  for (ll i = 2; i <= n; i++) {
    d = 0;
    for (ll j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        d += 2;
      }
    }
    d += 2;
    sq = sqrt(i);
    if (i == (sq * sq))
      d--;
    // cout << i << "=" << d << endl;
    ans += (i * d);
  }
  ans++;
  printf("%lld\\n", ans);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int test_cases = 1; // cin>>test_cases;
  for (int tc = 1; tc <= test_cases; tc++) {
    solve();
    // cout << "Case " << tc << ": " << solve() <<endl;
    // cout << "Case " << tc << ": "<<fixed<<setprecision(2)<<solve()<<endl;
  }
  return 0;
}
/*
    problems are the sign of life
*/
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded



#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long

void anmol() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

// const int N = 1e6 + 5 ;
// int a[N], nums2[N] , freq[N];

int32_t main() {

  anmol();

  int n;
  cin >> n;

  int a[n + 1] = {0};

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

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

      a[j]++;
    }
  }

  int sum = 0;

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

    sum += i * a[i];
  }

  cout << sum << endl;
}


Error: TLE

Fixed submission:



#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long

// const int N = 1e6 + 5 ;
// int a[N], nums2[N] , freq[N];
int func(int n) {

  int Count = 0;

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

    if (n % i == 0 && n / i != i) {

      Count += 2;
    }

    else if (n % i == 0 && (n / i == i)) {

      Count += 1;
    }
  }
  return Count;
}

int32_t main() {

  // anmol();

  int n;
  cin >> n;

  int sum = 0;

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

    sum += func(i) * i;
  }

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



#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long

void anmol() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

// const int N = 1e6 + 5 ;
// int a[N], nums2[N] , freq[N];

int32_t main() {

  anmol();

  int n;
  cin >> n;

  int a[n + 1] = {0};

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

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

      a[j]++;
    }
  }

  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i] * i;
  }

  cout << sum << endl;
}


Error: TLE

Fixed submission:



#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long

// const int N = 1e6 + 5 ;
// int a[N], nums2[N] , freq[N];
int func(int n) {

  int Count = 0;

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

    if (n % i == 0 && n / i != i) {

      Count += 2;
    }

    else if (n % i == 0 && (n / i == i)) {

      Count += 1;
    }
  }
  return Count;
}

int32_t main() {

  // anmol();

  int n;
  cin >> n;

  int sum = 0;

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

    sum += func(i) * i;
  }

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
#endif
  int n;
  cin >> n;

  long long ans = 0;
  for (int div = 1; div <= n; div++)
    for (int mul = div; mul <= n; mul += div)
      ans += mul;

  cout << ans;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <math.h>
using namespace std;

int main() {

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

#include <bits/stdc++.h>
#define ENDL '\\n'
#define N 10000007
using namespace std;
typedef unsigned long long int ulli;
bool prime[N];
ulli cantdiv[N];
void primos();
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  ulli resp = 1;
  cin >> n;
  primos();
  for (int i = 2; i <= n; ++i) {
    resp += (cantdiv[i]) * i;
  }
  cout << resp;
  return 0;
}

void primos() {
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j < N; j += i) {
      cantdiv[j]++;
    }
  }
  cantdiv[1] = 1;
  return;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ENDL '\\n'
#define MAX 10000000
using namespace std;
typedef unsigned long long int ulli;
ulli funcion(ulli n);
ulli arr[MAX];
ulli arreg[MAX] = {0};
ulli divsum(ulli x);
int main() {
  ulli n;
  cin >> n;
  cout << funcion(n);
  return 0;
}

ulli funcion(ulli n) {
  ulli resp = 0;
  for (ulli i = 1; i <= n; ++i) {
    if (arreg[i]) {
      resp += arreg[i];
    } else {
      ulli aux = divsum(i);
      resp += i * aux;
    }
    arreg[i] = resp;
  }
  return resp;
}

ulli divsum(ulli x) {
  if (arr[x])
    return arr[x];
  ulli resp = 0;
  for (ulli i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      resp += 2;
      if (i * i == x)
        resp -= 1;
    }
  }
  arr[x] = resp;
  return resp;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

long long f(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  long long x = 1;
  for (auto p : res) {
    x *= (p.second + 1);
  }
  return x;
}
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += i * f(i);
  }
  cout << ans << endl;
}
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 namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  auto f = [&](ll x) { return x * (x + 1) / 2; };

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * f(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++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<ll> cnt(1e8, 0);
  for (int i = 1; i <= n; i++) {
    int x = sqrt(i);
    for (int j = 1; j <= x; j++) {
      if (i % j == 0) {
        cnt.at(i) += 2;
      }
    }
    if (x * x == i)
      cnt.at(i)--;
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * cnt.at(i);
  }

  cout << ans << 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 namespace std;
using ll = long long;
using P = pair<int, int>;

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  ll counts = 0;
  for (int j = 1; j <= n; j++) {
    int hani = sqrt(j);
    counts = 0;
    for (int i = 1; i <= hani; i++) {
      if (j % i == 0)
        counts++; /*
cout << counts << " <- "<< j << endl;*/
    }
    if (hani * hani == j) {
      ans += j * (2 * counts - 1);
      // cout << ans << "a" << endl;
    } else {
      ans += j * 2 * counts;
      // cout << ans << "b" << endl;
    }
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\\n";
string no = "NO\\n";
#define PI 3.1415926535

ll dp[10000001];

void f(ll n) {
  for (ll i = 2; i <= n; i++) {
    ll num = i;
    while (num <= n) {
      dp[num]++;
      num += i;
    }
  }
}

int32_t main() {
  fastio;
  ll n, ans = 0;
  cin >> n;
  f(10000000);
  for (ll i = 1; i <= n; i++) {
    ans += i * (dp[i] + 1);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\\n";
string no = "NO\\n";
#define PI 3.1415926535

ll dp[10000001];

ll f(ll n) {
  ll cnt = 0;
  for (ll i = 2; i <= n; i++) {
    ll num = i;
    while (num <= n) {
      dp[num]++;
      num += i;
    }
  }
}

int32_t main() {
  fastio;
  ll n, ans = 0;
  cin >> n;
  f(n);
  for (ll i = 1; i <= n; i++) {
    ans += i * (dp[i] + 1);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 Author: Alokit Kumar
 */
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  int t, n, i, j, k, l = 0, m = 1, s, s1 = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    j = n / i;
    s = (j * (j + 1) * i) / 2;
    s1 += s;
  }
  cout << s1;
}


Error: TLE

Fixed submission:

/*
 Author: Alokit Kumar
 */
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  int t, n, i, j, k, l = 0, m = 1, s, s1 = 1;
  int dp[10000002];
  for (i = 1; i <= 10000000; i++)
    dp[i] = i;
  for (i = 2; i <= 10000000; i++) {
    if (dp[i] == i) {
      for (j = i * i; j <= 10000000; j += i) {
        if (dp[j] == j)
          dp[j] = i;
      }
    }
  }
  cin >> n;
  for (i = 2; i <= n; i++) {
    k = i;
    m = 1;
    if (dp[i] == i) {
      s1 += 2 * i;
      continue;
    }
    for (j = dp[i]; j * j <= k; j++) {
      if (k % j == 0) {
        s = 0;
        while (k % j == 0) {
          k = k / j;
          s++;
        }
        m = m * (s + 1);
      }
    }
    if (k != 1)
      m = m * 2;
    s1 += m * i;
  }
  cout << s1;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int M = 10000001;
ll a[M];
int main() {
  int N;
  cin >> N;
  fill(a, a + M, 1);
  for (ll i = 2; i < M; i++) {
    for (ll j = 1; i * j < M; j++) {
      a[i * j]++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += i * a[i];
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long n, ans = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long 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;

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main() {
  int64_t N, ans = 0;
  cin >> N;
  for (int64_t i = 1; i <= N; i++) {
    int64_t M = N / i;
    ans += i * M * (M + 1) / 2;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int64_t bunkai(int64_t N) {
  int ans = 1;
  int64_t a = 2;
  while (N >= a * a) {
    if (N % a == 0) {
      int tmp = 1;
      while (N % a == 0) {
        N /= a;
        tmp++;
      }
      ans *= tmp;
    } else
      a++;
  }
  if (N != 1)
    return ans * 2;
  else
    return ans;
}

int main() {

  int64_t N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++)
    ans += i * bunkai(i);
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long int
#define arr array
// power of 2 ...n&(n-1)==0

const int x = 1e7;
int m[x + 1];

int main() {
  FAST;
  // #ifndef ONLINE_JUDGE
  //	freopen("input.txt","r",stdin);
  //	freopen("output.txt","w",stdout);
  // #endif
  // ll testcase;
  // cin>>testcase;
  // for(ll t=0;t<testcase;t++)
  {

    int n;
    cin >> n;
    memset(m, 0, sizeof(m));
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= n; j += i) {
        m[j]++;
      }
    }
    unsigned ll ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += (ll)i * m[i];
    }
    cout << ans << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long int
#define arr array
// power of 2 ...n&(n-1)==0

int main() {
  FAST;
  // #ifndef ONLINE_JUDGE
  //	freopen("input.txt","r",stdin);
  //	freopen("output.txt","w",stdout);
  // #endif
  // ll testcase;
  // cin>>testcase;
  // for(ll t=0;t<testcase;t++)
  {

    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= n; j += i) {
        m[j]++;
      }
    }
    unsigned ll ans = 0;
    for (auto i : m) {
      ans += (ll)(i.first * i.second);
    }
    cout << ans << '\\n';
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int mxn = 1e7 + 2;

void solve() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<int> a(n + 1, 0);
  for (ll i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  for (ll i = 1; i <= n; i++) {
    sum += (ll)a[i] * i;
  }

  cout << sum;
}

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int mxn = 1e7 + 2;
ll a[mxn] = {};

void solve() {
  int n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i) {
      a[i + j]++;
    }
  }
  for (ll i = 1; i <= n; i++) {
    sum += a[i] * i;
  }

  cout << sum;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll t;
  solve();
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6 + 10;
ll prime[N], k; // RE就开小一点
bool isprime[N];
void Prime() {
  fill(isprime, isprime + N, 1);
  k = 0;
  prime[1] = 0;
  for (ll i = 2; i < N; i++) {
    if (isprime[i]) {
      prime[k++] = i;
      for (ll j = 2; i * j < N; j++)
        isprime[i * j] = 0;
    }
  }
}

// 质因子分解找因子数
ll solve(ll n) {
  ll cnt = 0, sum = 1;
  for (ll i = 0; i < k && prime[i] * prime[i] <= n; i++) {
    if (n % prime[i] == 0) {
      cnt = 0;
      while (n % prime[i] == 0) {
        cnt++;
        n /= prime[i];
      }
      sum *= (1 + cnt);
    }
  }
  if (n > 1)
    sum *= 2;
  return sum;
}
ll x[10000005], n;
int main() {
  for (int i = 1; i < 10000001; i++)
    for (int j = i; j < 10000001; j += i)
      x[j]++; // 存因子个数
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++)
    sum += x[i] * i;
  cout << sum;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6 + 10;
ll prime[N], k; // RE就开小一点
bool isprime[N];
void Prime() {
  fill(isprime, isprime + N, 1);
  k = 0;
  prime[1] = 0;
  for (ll i = 2; i < N; i++) {
    if (isprime[i]) {
      prime[k++] = i;
      for (ll j = 2; i * j < N; j++)
        isprime[i * j] = 0;
    }
  }
}

// 质因子分解找因子数
ll solve(ll n) {
  ll cnt = 0, sum = 1;
  for (ll i = 0; i < k && prime[i] * prime[i] <= n; i++) {
    if (n % prime[i] == 0) {
      cnt = 0;
      while (n % prime[i] == 0) {
        cnt++;
        n /= prime[i];
      }
      sum *= (1 + cnt);
    }
  }
  if (n > 1)
    sum *= 2;
  return sum;
}

int main() {
  Prime();
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++)
    sum += ll(i) * solve(i);
  //    for(int i=1;i<=n;i++)
  //        cout<<ll(i)*solve(i)<<endl;
  cout << sum;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define arep(a, i, n) for (int i = (a); i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define cinf(x, n)                                                             \\
  for (int i = 0; i < (n); i++)                                                \\
    cin >> x[i];
#define coutf(x, n)                                                            \\
  for (int i = 0; i < (n); i++)                                                \\
    cout << x[i] << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll a[10000001];

int main() {
  ll n;
  cin >> n;
  ull sum = 0;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i; j < n + 1; j += i) {
      a[j]++;
    }
  }
  arep(1, i, n + 1) { sum += i * a[i]; }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define arep(a, i, n) for (int i = (a); i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define cinf(x, n)                                                             \\
  for (int i = 0; i < (n); i++)                                                \\
    cin >> x[i];
#define coutf(x, n)                                                            \\
  for (int i = 0; i < (n); i++)                                                \\
    cout << x[i] << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll a[10000001];

int main() {
  ll n;
  cin >> n;
  ull sum = 0;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i; j < n + 1; j *= i) {
      a[j]++;
    }
  }
  arep(1, i, n + 1) { sum += i * a[i]; }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll tmp = N / i;
    ans += tmp * (tmp + 1) * i / 2;
  }

  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

// エラトステネスのふるいを作成
bool isPrime[10000001]; // ふるい
// int cntPrime[10000001]; // n個以下の素数の個数
int dp[10000001], cntTwo[10000001];

void prime_factorize(ll N) {
  // vector<P> res;
  for (int i = 0; i < 10000001; i++)
    isPrime[i] = true;
  isPrime[0] = false;
  isPrime[1] = false;
  // cntPrime[0] = 0;
  for (int i = 0; i < 10000001; i++) {
    if (isPrime[i]) {
      // cntPrime[i] = cntPrime[i-1] + 1;
      for (int j = 2 * i; j < 10000001; j += i)
        isPrime[j] = false;
    }
  }

  ll m = 3;
  while (m <= N) {
    if (isPrime[m]) {
      // cout << "isPrime" << endl;
      dp[m] = 2;
      m++;
      continue;
    }
    if (m % 2 == 0) {
      ll l = m / 2;
      cntTwo[m] = cntTwo[l] + 1;
      // cout << "m: " << m << ", cntTwo: " << cntTwo[m];
      dp[m] = dp[l] / (cntTwo[l] + 1) * (cntTwo[m] + 1);
      // if (cntTwo[l] != 0) dp[m] = dp[l] / cntTwo[l] * cntTwo[m];
      // else dp[m] = dp[l] * 2;
      m++;
      continue;
    }
    ll tmp = 1;
    for (ll a = 2; a * a <= m; ++a) {
      if (m % a != 0)
        continue;
      ll ex = 0;
      while (N % a == 0) {
        ++ex;
        m /= a;
      }
      tmp *= ex;
      // res.push_back({a, ex});
    }
    dp[m] = tmp;
    m++;
    // if (m != 1) res.push_back({m, 1});
  }
  // return res;
}

int main() {
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  dp[2] = 2;
  cntTwo[2] = 1;

  ll N;
  cin >> N;

  ll ans = 0;
  prime_factorize(N);

  for (int i = 1; i <= N; i++) {
    ans += i * dp[i];
  }
  cout << ans << endl;
  /*
  for (ll n = 2; n <= N; ++n) {
      if (dp[n/2] > 0) {

      }
      const auto &res = prime_factorize(n); // n の素因数分解
      ll tmp = 1;
      for (auto p : res) {
          tmp *= (p.second + 1);
      }
      dp[n] = tmp;
      ans += n * tmp;
  }
  */
  // cout << ans << endl;
  return 0;
}