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

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define endl "\\n"
typedef long long ll;
const int mx = 10000001;
int dp[mx];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  dp[1] = 1;
  for (int i = 2; i < mx; i++) {
    if (!dp[i]) {
      for (int j = i; j < mx; j += i)
        dp[j] = i;
    }
  }
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < 100; i++)
    ;
  for (int i = 1; i <= n; i++) {
    map<int, int> mp;
    int x = i;
    while (x != dp[x]) {
      mp[dp[x]] += 1;
      x /= dp[x];
    }
    if (x != 1)
      mp[dp[x]] += 1;
    int res = 1;
    map<int, int>::iterator it = mp.begin();
    for (; it != mp.end(); it++) {
      x = (it->second);
      x += 1;
      res *= x;
    }
    ////cout<<i<<" "<<res<<endl;
    ans += i * res;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp make_pair
#define loop(a, n) for (long long i = a; i < n; i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)
    return true;
  return false;
}
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first)
    return a.second > b.second;
  return a.first < b.first;
}
ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])
      continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }
  }
}
int N = 10000003;
unordered_map<ll, ll> m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll ans = 0;
  ll n;
  cin >> n;

  // dp[1]=0;

  for (int i = 2; i <= n; i++) {
    for (int j = 1; j * i <= n;) {
      m[j * i]++;
      j++;
    }
  }
  for (int i = 0; i <= n; i++) {
    ans += i * (m[i] + 1);
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template <class T> inline bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

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

  ll res = 0;
  for (int i = 1; i <= N; ++i) {
    ll num = N / i;
    res += num * (i + i * num) / 2;
  }
  cout << res << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);

  solve();

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template <class T> inline bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

int cnt(int n) {
  int res = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ++res;
      if (i != n / i)
        ++res;
    }
  }
  return res;
}

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

  ll res = 0;
  for (ll i = 1; i <= N; ++i) {
    res += i * cnt(i);
  }
  cout << res << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);

  solve();

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

#include <bits/stdc++.h>

using namespace std;

#define u64 uint64_t
#define i64 int64_t
#define mod 1000000007
#define inf 1e18
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  /**************************/

  u64 a;
  cin >> a;
  u64 ans = 0;
  for (u64 i = 1; i <= a; ++i) {
    u64 j = a / i;
    ans += (j * (j + 1) * i) / 2;
  }
  cout << ans;
  /**************************/
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define u64 uint64_t
#define i64 int64_t
#define mod 1000000007
#define inf 1e18
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

uint32_t divisor(u64 a) {
  uint32_t div = 0;
  for (uint32_t i = 1; i <= sqrt(a); ++i) {
    if (a % i == 0) {
      if (a / i == i)
        div++;
      else
        div += 2;
    }
  }
  return div;
}

u64 sum(u64 i) {
  u64 ans = 0;
  for (u64 j = 1; j <= i; ++j) {
    ans += j * divisor(j);
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  /**************************/

  u64 a;
  cin >> a;

  cout << sum(a);

  /**************************/
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N, sum = 0;
int main() {
  cin >> N;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    long long t = N / i;
    ans += (t * (t + 1) / 2) * i;
    // for(int j=1;j<=N;j++){
    // if(i%j==0){
    //     sum+=i;
    //     }
    // }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

// Abu Hurayra (HurayraIIT)
// IIT, Jahangirnagar University

#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int> vi;

#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define sz(a) int((a).size())
#define space " "
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
#define pi acos(-1.0)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define MOD 1000000007
#define PRECISION(x) cout << fixed << setprecision(x);

int main() {
  fast_io

      LL n,
      i, j, ans = 0;
  cin >> n;
  LL divs[n + 1] = {0};

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

// Abu Hurayra (HurayraIIT)
// IIT, Jahangirnagar University

#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int> vi;

#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define sz(a) int((a).size())
#define space " "
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
#define pi acos(-1.0)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define MOD 1000000007
#define PRECISION(x) cout << fixed << setprecision(x);

LL div(LL n) {
  LL i, cnt = 0;
  for (i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      cnt += 2;
    if (n % i == 0 && i == n / i)
      cnt--;
  }
  return cnt;
}

int main() {
  fast_io

      LL n,
      i, ans = 0;
  cin >> n;

  for (i = 1; i <= n; i++) {
    ans += i * div(i);
  }

  cout << ans << endl;

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define endl "\\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y)                                                           \\
  cout << #x << " : " << x << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0);
typedef long long ll;
using namespace std;

int main() {
  FASTIO

  ll n;
  cin >> n;

  vector<ll> ans(n + 10, 1);
  for (ll i = 2; i <= n; i++) {
    if (ans[i] == 1) {
      ans[i] = 2;
      for (ll j = 2; i * j <= n; j++) {
        ll val = i * j;
        ll count = 0;
        while (val % i == 0) {
          val /= i;
          count++;
        }

        ans[i * j] *= (count + 1);
      }
    }
  }

  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    if (i != 1 && ans[i] == 1)
      ans[i] = 2;
    // debug(i * ans[i])
    res += (i * ans[i]);
  }

  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define endl "\\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y)                                                           \\
  cout << #x << " : " << x << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0);
typedef long long ll;
using namespace std;

bool primes[3200];

int main() {
  FASTIO

  vector<ll> primeList;
  for (ll i = 2; i * i <= 3200; i++) {
    if (primes[i] == false) {
      for (ll j = i; i * j <= 3200; j++)
        primes[i * j] = true;
    }
  }

  for (ll i = 2; i <= 3200; i++) {
    if (primes[i] == false)
      primeList.push_back(i);
  }

  ll n;
  cin >> n;

  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ll val = i;
    ll product = 1;

    for (ll d : primeList) {
      ll count = 0;
      if (d * d > val)
        break;
      while (val % d == 0) {
        val /= d;
        count++;
      }

      product *= (count + 1);
    }

    if (val > 1)
      product *= 2;
    // debug2(i, product)
    ans += (i * product);
  }
  cout << ans << 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);
  int n;
  cin >> n;
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      s += j;
    }
  }
  cout << s;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long divisors(int k) {
  long long d = 1;
  for (int i = 2; i * i <= k; i++) {
    long long a = 0;
    while (k % i == 0) {
      a += 1;
      k /= i;
    }
    if (a > 0) {
      d *= (a + 1);
    }
  }
  if (k > 1) {
    d *= 2;
  }
  return d;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    s += i * divisors(i);
  }
  cout << s;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll divisor(ll n) {

  ll c = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      c++;
      if (i * i != n)
        c++;
    }
  }
  // 昇順に並べる
  return c;
}

int main() {

  ll N;

  cin >> N;

  ll sum = 0;

  vector<ll> Ys(N + 1, 2);

  Ys[1] = 1;

  for (ll i = 2; i <= N; i++) {

    if (i * i > N) {

      break;
    }

    for (ll j = i; j <= N; j++) {

      if (i * j > N) {

        break;
      }

      Ys[i * j]++;

      if (i != j) {

        Ys[i * j]++;
      }
    }
  }

  for (ll i = 1; i <= N; i++) {

    sum = sum + i * Ys[i];
  }

  cout << sum << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll divisor(ll n) {

  ll c = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      c++;
      if (i * i != n)
        c++;
    }
  }
  // 昇順に並べる
  return c;
}

int main() {

  ll N;

  cin >> N;

  ll sum = 0;

  for (ll i = 1; i <= N; i++) {

    sum += divisor(i) * i;
  }

  cout << sum << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (long long(i) = 0; (i) < (n); ++(i))
#define ref(i, a, b) for (long long(i) = (a); (i) <= (b); ++(i))
#define endl '\\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
const int mx = 2e7 + 5;
long long p[mx];
long long d[mx];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  /*freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
*/
  int n;
  cin >> n;
  ref(i, 1, n) d[i] = 1;
  p[1] = 1;
  p[2] = 0;
  d[1] = 1;
  int div, count;
  for (int i = 2; i <= n; ++i) {
    if (p[i] == 0) {
      d[i] = 2;
      for (int j = i * 2; j <= n; j += i) {
        p[j] = 1;
        div = j;
        count = 0;
        while (div % i == 0) {
          ++count;
          div = div / i;
        }
        d[j] = d[j] * (count + 1);
      }
    }
  }
  ll sum = 0;
  ref(i, 1, n) sum += i * d[i];
  cout << sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (long long(i) = 0; (i) < (n); ++(i))
#define ref(i, a, b) for (long long(i) = (a); (i) <= (b); ++(i))
#define endl '\\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
const int mx = 1e7 + 5;
vector<int> a;
bool prime[mx];
map<ll, ll> m;
// en son int ler long long a
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  /*freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
*/
  ll N;
  cin >> N;
  ref(i, 1, N) prime[i] = true;
  prime[1] = false;
  prime[2] = true;
  m[4] = 1;
  for (int i = 2; i * i <= N; ++i) {
    if (prime[i] == true) {
      m[i * i] = true;
      for (int j = i * i; j <= N; j += i)
        prime[j] = false;
    }
  }
  int p;
  long long ans = 1;
  // cout<<prime[5]<<endl;
  for (int i = 1; i <= N; ++i)
    if (prime[i] == true) {
      a.pb(i); /*cout<<i<<endl;*/
    }
  // cout<<a.size();
  long long sum = 0;
  for (int jk = 1; jk <= N; ++jk) {
    ll n = jk;
    ans = 1;
    for (int i = 0; i < a.size(); ++i) {
      // cout << p <<" ";
      // ans=1;
      p = a[i];
      int count = 0;
      if (p * p * p > n)
        break;
      while (n % p == 0) {
        n = n / p;
        ++count;
      }
      ans = ans * (count + 1);
    }
    // cout<<ans<<endl;
    // cout << ans << " ";
    if (prime[n] == true)
      ans = ans * 2;
    else if (m[n])
      ans = ans * 3;
    else if (n != 1)
      ans = ans * 4;
    // cout<<ans<<endl;
    sum = sum + jk * ans;
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007

const long long mx = 1e7 + 1;
long long a[mx] = {0};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= n; j += i) {
      a[j]++;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += (i * a[i]);
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007

ll getDiv(ll n) {
  ll 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() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  ll a[n];
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (getDiv(i) * i);
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

#define TC                                                                     \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
typedef long long ll;

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll n, a, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    a = n / i;
    ans += ((a * (a + 1) * i) / 2);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

/// b. sum of divisors
#include <math.h>
#include <stdio.h>
int main() {
  int n;
  scanf("%d", &n);
  long long int sum = 0;

  for (int i = 1; i <= n; i++) {
    int d = 0;
    for (int j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (j == sqrt(i))
          d++;
        else
          d += 2;
      }
    }
    sum += i * d;
  }
  printf("%lld", sum);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
// ll s[500500];
const int N = 1e7 + 5;
ll f[N], n, ans;
int main() {
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i)
      f[j]++;
  }
  cin >> n;
  for (int i = 1; i <= n; i++)
    ans += f[i] * i;
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

/**
 *    Author  : Ador
 *    Created : 24.07.2020
 **/
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
ll f(ll x) {
  ll i, cnt = 0;
  for (i = 1; i <= x; ++i) {
    if (!(x % i))
      ++cnt;
  }
  return x * cnt;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin) ;
  // freopen("output.txt", "w", stdout) ;
  ll n, i, sum = 0;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    sum += f(i);
  }
  cout << sum << "\\n";
  return 0;
}
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;
  for (int i = 1; i <= n; ++i)
    ans += (i + n / i * i) * (n / i) / 2;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*
                                                  __          __
      /\\   |   |     /\\   |  | |  |     /\\   | / |  )   /\\   |  )
     /__\\  |   |    /__\\  |--| |  |    /__\\  |<  |-<   /__\\  |-<
    /    \\ |__ |__ /    \\ |  | \\__/   /    \\ | \\ |__) /    \\ |  \\

*/

#import <bits/stdc++.h>
typedef long long ll;
#define num 10000010
#define forll(i, a, b, c) for (int i = a; i <= b; i += c)
#define forll2(i, a, b, c) for (int i = a; i >= b; i -= c)
#define pb(n) push_back(n)

using namespace std;

map<int, int> m;
map<int, ll> o;

void nod() {
  int p = sqrt(num);
  forll(i, 2, p, 1) {
    if (!m[i]) {
      forll(j, i + i, num, i) { m[j]++; }
    }
  }
  m[1]++;
  o[1] = 1;
  forll(i, 2, num, 1) {
    m[i] += 2;
    o[i] = o[i - 1] + (i * m[i]);
  }
}

int main() {
  nod();
  int n;
  cin >> n;
  cout << o[n] << "\\n";
}