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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

lli f[10000007];

int main() {
  lli i, j, n, p, val;
  for (i = 1; i <= 10000000; i++) {
    for (j = i; j <= 10000000; j += i)
      f[j]++;
  }
  cin >> n;
  val = 0;
  for (i = 1; i <= n; i++) {
    val += (i * f[i]);
  }
  cout << val << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

bool prime[10000007];
vector<lli> pm;
lli f[10000007];

void SieveOfEratosthenes(lli n) {
  // Create a boolean array "prime[0..n]" and initialize
  // all entries it as true. A value in prime[i] will
  // finally be false if i is Not a prime, else true.
  // bool prime[n+1];
  memset(prime, true, sizeof(prime));

  for (lli p = 2; p * p <= n; p++) {
    // If prime[p] is not changed, then it is a prime
    if (prime[p] == true) {
      // Update all multiples of p greater than or
      // equal to the square of it
      // numbers which are multiple of p and are
      // less than p^2 are already been marked.
      for (lli i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
  for (lli i = 2; i <= n; i++) {
    if (prime[i])
      pm.push_back(i);
  }
}

int main() {
  lli i, j, n, p, val;
  SieveOfEratosthenes(10000007);
  f[1] = 1;
  for (i = 2; i <= 1000000; i++) {
    n = i;
    j = 0;
    val = 1;
    while (n > 1) {
      p = 0;
      while (n % pm[j] == 0) {
        n /= pm[j];
        p++;
      }
      val *= (p + 1);
      j++;
    }
    f[i] = val;
  }
  cin >> n;
  val = 0;
  for (i = 1; i <= n; i++) {
    val += (i * f[i]);
  }
  cout << val << "\\n";
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define cpresent(c, x) ((c).find(x) != (c).end())
#define vpresent(c, x) (find(all(c), x) != (c).end())
#define endl '\\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(Args...)
#endif
using ll = long long;
using namespace __gnu_pbds;
using namespace std;
template <class T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll n;

void shit() {
  cin >> n;
  ll ans = 0;
  // a(n) = Sum_{m=1..floor(sqrt(n))} m*(m+floor(n/m))*(floor(n/m)+1-m)
  for (ll i = 1; i <= sqrt(n); ++i) {
    ans += i * (i + (n / i)) * (n / i + 1 - i);
  }
  n = sqrt(n);
  ll extra = n;
  extra *= (n + 1);
  extra *= (2 * n + 1);
  extra /= 6; // n*(n+1)*(2*n+1)/6
  ans -= extra;
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  // int t; cin >> t;
  // while(t--)
  shit();
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define cpresent(c, x) ((c).find(x) != (c).end())
#define vpresent(c, x) (find(all(c), x) != (c).end())
#define endl '\\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(Args...)
#endif
using ll = long long;
using namespace __gnu_pbds;
using namespace std;
template <class T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll divno(ll n) {
  ll ret = 0;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret++;
      if (n / i != i)
        ret++;
    }
  }
  return ret;
}

ll n;

void shit() {
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    ans += i * divno(i);
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  // int t; cin >> t;
  // while(t--)
  shit();
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  vector<int> A(N + 10, 0);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; i * j <= N; j++) {
      A[i * j]++;
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += i * A[i];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

vector<int> sieve(int n) {
  vector<int> res(n);
  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;
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N + 10);
  A = sieve(N + 1);

  vector<int> fac(N + 10, 2);
  fac[1] = 1;

  int ans = 1;
  for (int i = 2; i <= N; i++) {
    int now = 0;
    for (int j = A[i]; j <= sqrt(i); j++) {
      if (i % j == 0) {
        now++;
        if (i / j != j)
          now++;
      }
    }
    // cout << now << endl;
    ans += (now + 2) * i;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

long long int f(long long int x) {
  long long int count = 0;
  for (long long int i = 1; i <= sqrt(x); i++) {
    if (x % i == 0) {
      if (x / i == i)
        count++;
      else
        count += 2;
    }
  }
  return count;
}

int main() {
  long long int n;
  cin >> n;
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    sum += i * f(i);
  }
  cout << sum << endl;
  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(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n;
  long long sum = 0;
  cin >> n;

  /*
  ..................
  This general solution to find the factors of num can be interchanged
  since both inner and outer loop are independent.
  ......................
  ### General Sol:
  for(int num=1;num<=n;num++)
  {
      for(int den=1;den <=n;den++)
      {
          if(num%den == 0)
          {
              sum += num;
          }
      }
  }

  #### Interchanging inner and outer loop:-

  for(int den=1;den<=n;den++)
  {
      for(int num=1;num <=n;num++)
      {
          if(num%den == 0)
          {
              sum += num;           //The result will be same but we can now
  interpret the
                                    //question differently.
          }
      }
  }

  #### we are finding for every 'den' its multiples and the sum of it.
  thus g(x) = sum of multiples of x can be found easily using AP.

  and we have to find  sum of g(1 -> N)
  .......................
 */

  for (long long i = 1; i <= n; i++) {
    long long y = floor(n / i); // highest multiple of i <= n
    sum += (i * y * (y + 1)) / 2;
  }

  cout << sum << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n;
  long long sum = 0;
  cin >> n;
  for (int num = 1; num <= n; num++) {
    for (int den = 1; den <= num; den++) {
      if (num % den == 0) {
        sum += num;
      }
    }
  }
  cout << sum << endl;

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

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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for (int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int, int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 8;
const double pi = 3.14159265359;
void solve() {
  int n;
  cin >> n;
  int ans = 0;
  int a[n + 1];
  for (int i = 0; i <= n; i++)
    a[i] = 1;
  a[0] = 0;
  for (int i = 2; i <= n; i++)
    for (int j = i; j <= n; j += i)
      a[j] += 1;
  for (int i = 1; i <= n; i++)
    ans += i * a[i];
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
}

Error: TLE

Fixed submission:

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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for (int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int, int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 8;
const double pi = 3.14159265359;
int divi(int n) {
  int ans = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        ans++;
      else
        ans += 2;
    }
  }
  return ans;
}
void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * divi(i);
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define fr first
#define sec second
#define rep(i, n) for (i = 0; i < n; i++)
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define M 1000000007
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define open freopen("input.txt", "r", stdin);
#define close freopen("output.txt", "w", stdout);
#define M_PI 3.14159265358979323846
#define pp pair<int, int>
#define nn 100003

int main() {
  ios;
  ll n, i, ans = 0;
  cin >> n;
  ll divisors[n + 1];
  memset(divisors, 0, sizeof(divisors));
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j * i <= n; j++)
      divisors[i * j]++;
  }
  rep(i, n) ans += ((i + 1) * divisors[i + 1]);
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define fr first
#define sec second
#define rep(i, n) for (i = 0; i < n; i++)
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define M 1000000007
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define open freopen("input.txt", "r", stdin);
#define close freopen("output.txt", "w", stdout);
#define M_PI 3.14159265358979323846
#define pp pair<int, int>
#define nn 100003

ll divisors(ll x) {
  bool hash[x + 1];
  memset(hash, true, sizeof(hash));
  for (ll p = 2; p * p < x; p++)
    if (hash[p] == true)
      for (ll i = p * 2; i < x; i += p)
        hash[i] = false;

  ll total = 1;
  for (ll p = 2; p <= x; p++) {
    if (hash[p]) {
      ll count = 0;
      if (x % p == 0) {
        while (x % p == 0) {
          x /= p;
          count++;
        }
        total *= (count + 1);
      }
    }
  }
  return total;
}

int main() {
  ios;
  ll n, i, ans = 0;
  cin >> n;
  rep(i, n) ans += ((i + 1) * divisors(i + 1));
  cout << ans;
  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++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll k = n / i;
    ans += i * k * (k + 1) / 2;
  }
  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 rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

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

ll p[10000010];

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

  for (int i = 1; i <= n; i++) {
    map<ll, ll> mp = prime_factor(i);
    ll tmp = 1;
    for (auto v : mp) {
      tmp *= (v.second + 1);
    }
    p[i] = tmp;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += p[i] * i;
  }

  cout << ans << endl;

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ll;
const double eps = 1e-8;
const double inf = 0x3f3f3f3f;
const int maxn = 1e7 + 15;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; };

bool isPrime(ll n) {
  if (n == 2 || n == 3)
    return true;
  ll cnt = sqrt(n);
  for (ll i = 2; i <= cnt; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}
ll Count(ll n) {
  if (n == 1)
    return 1;
  if (n == 2 || n == 3)
    return 2;
  ll s = 1;
  // ll cnt=sqrt(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll a = 0;
      while (n % i == 0) {
        n /= i;
        a++;
      }
      s = s * (a + 1);
    }
  }
  if (n > 1)
    s = s * 2;
  return s;
}

int num[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, i, j;
  ll ans = 1;
  cin >> n;
  num[1] = 1;
  for (i = 2; i <= n; i++) {
    for (j = i; j <= n; j += i)
      num[j]++;
  }
  for (i = 2; i <= n; i++) {
    num[i]++;
    ans += num[i] * i;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ll;
const double eps = 1e-8;
const double inf = 0x3f3f3f3f;
const int maxn = 200015;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; };

bool isPrime(ll n) {
  if (n == 2 || n == 3)
    return true;
  ll cnt = sqrt(n);
  for (ll i = 2; i <= cnt; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}
ll Count(ll n) {
  if (n == 1)
    return 1;
  if (n == 2 || n == 3)
    return 2;
  ll s = 1;
  // ll cnt=sqrt(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll a = 0;
      while (n % i == 0) {
        n /= i;
        a++;
      }
      s = s * (a + 1);
    }
  }
  if (n > 1)
    s = s * 2;
  return s;
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, i;
  ll ans = 1;
  cin >> n;
  for (i = 2; i <= n; i++) {
    ll k;
    k = Count(i);
    // cout<<k<<endl;
    ans += k * i;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <unordered_map>
using namespace std;
#define rep_1(i, m, n) for (int i = m; i <= n; i++)
#define mem(st) memset(st, 0, sizeof st)
int read() {
  int res = 0, ch, flag = 0;
  if ((ch = getchar()) == '-') // 判断正负
    flag = 1;
  else if (ch >= '0' && ch <= '9') // 得到完整的数
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    res = res * 10 + ch - '0';
  return flag ? -res : res;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
#define int long long
int primes[N];
signed main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      sum += j;
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <unordered_map>
using namespace std;
#define rep_1(i, m, n) for (int i = m; i <= n; i++)
#define mem(st) memset(st, 0, sizeof st)
int read() {
  int res = 0, ch, flag = 0;
  if ((ch = getchar()) == '-') // 判断正负
    flag = 1;
  else if (ch >= '0' && ch <= '9') // 得到完整的数
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    res = res * 10 + ch - '0';
  return flag ? -res : res;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
#define int long long
int primes[N];
int solve(int x) {
  unordered_map<int, int> primes;
  for (int i = 2; i <= x / i; i++)
    while (x % i == 0) {
      x /= i;
      primes[i]++;
    }
  if (x > 1)
    primes[x]++;
  ll res = 1;
  for (auto p : primes)
    res = res * (p.second + 1);
  return res;
}
signed main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    sum += i * solve(i);
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
using ll = long long;
int main() {
  int X;
  ll ans = 0;
  cin >> X;
  for (int i = 1; i <= X; i++) {
    ll n = X / i, un = n * i;
    ans += n * (un + i) >> 1;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
list<int> prime;
unordered_map<int, bool> is_prime;
void generate() {
  bitset<10000> computed;
  prime.push_back(2);
  for (int i = 3; i < 1e4; i += 2) {
    if (!computed[i]) {
      is_prime[i] = 1;
      prime.push_back(i);
      for (int j = i * i; j < 1e4; j += i)
        computed[j] = 1;
    }
  }
}
int faktor(int);
int main() {
  generate();
  int N;
  cin >> N;
  ll ans = 1;
  for (int i = 2; i <= N; i++)
    ans += (ll)i * faktor(i);
  cout << ans << endl;
}
int faktor(int x) {
  if (is_prime[x])
    return 2;
  int ans = 1;
  for (int it : prime) {
    if (it > sqrt(x))
      break;
    if (x % it == 0) {
      int cnt = 0;
      while (x % it == 0)
        x /= it, ++cnt;
      ans *= cnt + 1;
    }
  }
  return (x > 1 ? ans << 1 : ans);
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#include <numeric>
using namespace std;
const int sz = 1e7 + 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 NOD(ll int n) {

  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      arr[j]++;
}

int main() {

  ll int n;
  cin >> n;
  NOD(n);
  unsigned ll int k = 0;
  for (int i = 1; i <= n; i++) {
    k += (arr[i] * i);
  }

  cout << k << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#include <numeric>
using namespace std;
const int sz = 1e7 + 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;

ll int NOD(ll int n) {

  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i)
      arr[j]++;

  return arr[n];
}

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>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {

  ll n;
  cin >> n;

  map<ll, ll> count;

  ll sum = 0;

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

    ll x = (terms * (terms + 1) * i) / 2;
    sum += x;
  }
  cout << sum;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {

  ll n;
  cin >> n;

  map<ll, ll> count;

  for (int i = 1; i <= n; i++)
    count[i]++;

  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j <= n; j += i)
      count[j]++;
  }

  ll sum = 0;

  for (ll i = 1; i <= n; i++)
    sum += i * count[i];

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

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

int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  vector<long long> v(N + 1, 0);
  for (long long i = 1; i <= N; i++) {
    long long t = N / i;
    ans += t * (i + i * t) / 2;
    for (long long j = 1; j < N / i; j++)
      v[i * j]++;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

long long f(long long n) {
  long long ret = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret++;
      if (i * i != n)
        ret++;
    }
  }
  return ret;
}

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;
}