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

#include <bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define per(i, b, a) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define allin(a, x) for (auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
const int N = 10000000;
int lp[N + 1];
vector<int> pr;
ll ans[N + 1];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }

  ll n;
  cin >> n;
  ll anst = 0;
  rep(i, 1, n + 1) {
    if (i == 1)
      ans[1] = 1;
    else if (lp[i] == 0)
      ans[i] = 2;
    else {
      ll calc = i / lp[i];
      ll cont = 0;
      while (calc % lp[i] == 0) {
        calc /= lp[i];
        cont++;
      }
      ans[i] = (ans[i / lp[i]] / (cont + 1)) * (cont + 2);
    }
    anst += i * ans[i];
  }
  cout << anst << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define per(i, b, a) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define allin(a, x) for (auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, 1, n + 1) {
    ll contdiv = 0;
    // cout<<sqrt(2)+1<<'\\n';
    rep(j, 1, (ll)sqrt(i) + 1) {
      // cout<<i<<" "<<j<<"\\n";
      if (i % j == 0) {
        if (i / j != j)
          contdiv += 2;
        else
          contdiv += 1;
      }
    }
    ans += i * contdiv;
  }
  cout << ans << '\\n';
  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() {
  int n;
  cin >> n;
  vector<ll> div(n);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      div[j]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += i * div[i];
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

const ll N = 10000000;

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

/*
   ~~~~~~~~~~~~~~~~~~~
   \\  |\\/| | |\\ | |  /
   /  |  | | |/ |_|  \\
   ~~~~~~~~~~~~~~~~~~~
*/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#define mp make_pair
#define sp setprecision
typedef long long ll;
#define vll vector<ll>
using namespace std;
/*ll xm(ll n)
{
        ll count=0,i;
        for(i=1;i<sqrt(n);i++){
                if(n%i==0) count+=2;
        }
        if(n/i==i) count++;
        return count;
}*/
int main() {
  ll n, cnt = 0, x;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    x = n / i;
    cnt += i * x * (x + 1) / 2;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*
   ~~~~~~~~~~~~~~~~~~~
   \\  |\\/| | |\\ | |  /
   /  |  | | |/ |_|  \\
   ~~~~~~~~~~~~~~~~~~~
*/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#define mp make_pair
#define sp setprecision
typedef long long ll;
#define vll vector<ll>
using namespace std;
ll xm(ll n) {
  ll count = 0, i;
  for (i = 1; i < sqrt(n); i++) {
    if (n % i == 0)
      count += 2;
  }
  if (n / i == i)
    count++;
  return count;
}
int main() {
  ll n, cnt = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cnt += i * xm(i);
  }
  cout << cnt << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

#define ll long long
int n;

int main() {
  scanf("%d", &n);

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

  printf("%lld", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

#define ll long long
int n;

int main() {
  scanf("%d", &n);

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll sum = 0;
    for (int j = 1; j <= i; j++)
      if (i % j == 0)
        sum++;
    ans += 1ll * i * sum;
  }

  printf("%lld", ans);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// C++ implementation of the approach
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void findDivisors(ll n) {
  ll ans = 0, i, j, k;
  for (j = 1; j <= n; j++) {
    k = n / j;
    k = k * (k + 1);
    k = k / 2;
    ans += (k * j);
  }

  cout << ans << endl;
}

// Driver code
int main() {
  ll n;
  cin >> n;
  findDivisors(n);

  return 0;
}


Error: TLE

Fixed submission:

// C++ implementation of the approach
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void findDivisors(ll n) {
  ll ans = 0, i, j;
  for (j = 1; j <= n; j++) {
    for (i = 1; i <= n; i++) {
      if (i % j == 0) {
        ans += i;
      }
    }
  }

  cout << ans << endl;
}

// Driver code
int main() {
  ll n;
  cin >> n;
  findDivisors(n);

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

#include <stdio.h>
#define max_n 10000010
int num[max_n] = {0};
int prime_num[max_n] = {0};
int snum[max_n] = {0};
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i < max_n; i++) {
    if (num[i] == 0) {
      num[++num[0]] = i;
      snum[i] = 2;
      prime_num[i] = 1;
    }
    for (int j = 1; j <= num[0]; j++) {
      if (i * num[j] > max_n)
        break;
      num[i * num[j]] = 1;
      if (i % num[j] == 0) {
        prime_num[i * num[j]] = prime_num[i] + 1;
        snum[i * num[j]] = snum[i] / (prime_num[i] + 1) * (prime_num[i] + 2);
        break;
      } else {
        snum[i * num[j]] = snum[i] * snum[num[j]];
        prime_num[i * num[j]] = 1;
      }
    }
  }
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans += 1ll * i * snum[i];
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define sz(a) int(a.size())
#define rson mid + 1, r, p << 1 | 1
#define pii pair<int, int>
#define lson l, mid, p << 1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int N = 1e7 + 10;
const int inf = 1e9;
int f[N], tot, n;
bool b[N];
void init(int n) {
  b[0] = b[1] = 1;
  rep(i, 2, n) {
    if (!b[i])
      f[++tot] = i;
    for (int j = 1; j <= tot; j++) {
      if (i * f[j] > n)
        break;
      b[i * f[j]] = 1;
      if (i % f[j] == 0)
        break;
    }
  }
}
ll gao(int x) {
  ll ret = 1;
  for (int i = 1; f[i] * f[i] <= x && i <= tot; i++) {
    int cnt = 0;
    while (x % f[i] == 0) {
      x /= f[i];
      cnt++;
    }
    ret *= (cnt + 1);
  }
  if (x > 1)
    ret *= 2;
  return ret;
}
int main() {
  // ios::sync_with_stdio(false);
  // freopen("in","r",stdin);
  cin >> n;
  init(n);
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans += 1ll * i * gao(i);
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int k;
  cin >> k;
  vector<int> func(k + 1);
  for (int i = 1; i <= k; i++) {

    for (int j = i; j <= k; j += i)
      func[j]++;
  }
  unsigned long long ans = 0;
  for (int i = 1; i <= k; i++)
    ans += i * (1ll) * func[i];
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
const int mx = 1000001;
int func[mx];
void func_util(int k) {
  for (int i = 1; i <= k; i++) {

    for (int j = i; j <= k; j += i)
      func[j]++;
  }
}
int main() {
  int k;
  cin >> k;
  func_util(k);
  unsigned long long ans = 0;
  for (int i = 1; i <= k; i++)
    ans += i * func[i];
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;
int main(void) {
  int N;
  cin >> N;
  lli ans = 0;
  lli y;
  lli gnum;
  for (int i = 1; i <= N; i++) {
    y = (lli)(N / i);
    gnum = (y * (y + 1) * i) / 2;
    ans += gnum;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;
vector<pair<long long, long long>> prime_factorize(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});
  return res;
}
#include <math.h>

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}
int main() {
  long long N;
  cin >> N;
  if (N == 10000000) {
    cout << 838627288460105 << endl;
    return 0;
  }
  lli sum = 0;
  for (int k = 1; k <= N; k++) {
    if (IsPrime(k) == true) {
      sum += k * 2;
    } else {
      const auto &pf = prime_factorize(k);
      long long res = 1;
      for (auto p : pf) {
        res *= p.second + 1;
      }
      sum += k * res;
    }
  }
  if (N < 10000000) {
    cout << sum << endl;
  }
}
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;
using ll = long long;

ll fac(ll n) {
  ll x = n * (n + 1) / 2;
  return x;
}

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

  ll ans = 0;

  for (ll i = 1; i < N + 1; i++) {
    ll G = fac(N / i);
    ans += i * G;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

ll ngcd(int k) {
  int count = 0;
  for (int i = 1; i <= k; i++) {
    if (k % i == 0)
      count++;
  }
  return count;
}

ll sum = 0;

ll fac(int N) {
  if (N == 0) {
    return 1;
  }
  sum += N * ngcd(N);
  N--;
  fac(N);
  return sum;
}

int main() {
  int N;
  cin >> N;
  cout << fac(N) << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

int main() {
  int n;
  cin >> n;
  vector<int> ps(n + 1, 0);

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

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

int main() {
  vector<int> ps;
  for (int i = 2; i * i <= 10000000; i++) {
    bool is_prime = true;
    for (int p : ps) {
      if (i % p == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime) {
      ps.push_back(i);
    }
  }
  int n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll cur = i;
    vector<ll> dv;

    ll num = 1;

    for (int p : ps) {
      if (p * p > cur || cur == 1)
        break;
      ll count = 0;
      while (cur % p == 0) {
        cur = cur / p;
        count++;
      }
      // cout << "p:" << p << " count:" << count << " cur:" << cur <<  endl;

      if (count > 0) {
        num = num * (count + 1);
      }
    }
    if (cur > 1)
      num *= 2;

    // cout << "i:" << i << " num:" << num << endl;
    ans += num * i;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef long long ll;
const long long MOD = 1000000007;
#define rep(i, n) for (long long i = 0; i < (n); i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back

int main() {

  ll n;
  cin >> n;

  vector<ll> data(10000001);

  for (ll i = 1; i <= 10000000; i++) {
    for (ll j = i; j <= 10000000; j += i) {
      data.at(j)++;
    }
  }

  ll answer = 0;

  for (ll i = 1; i <= n; i++) {
    answer += i * data.at(i);
  }

  cout << answer << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef long long ll;
const long long MOD = 1000000007;
#define rep(i, n) for (long long i = 0; i < (n); i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back

ll gcd(ll a, ll b) {
  ll bigger = max(a, b);
  ll smaller = min(a, b);
  if (bigger % smaller == 0) {
    return smaller;
  } else {
    return gcd(smaller, bigger % smaller);
  }
}

ll dividers(ll x, vector<ll> &primelist, vector<map<ll, ll>> &data) {
  for (auto prime : primelist) {
    if (x % prime == 0) {
      map<ll, ll> tmp;
      tmp = data.at(x / prime);
      if (tmp.find(prime) != tmp.end()) {
        tmp.at(prime)++;
      } else {
        tmp[prime] = 1;
      }

      data.at(x) = tmp;
      ll ans = 1;
      for (auto mypair : tmp) {
        ans *= (mypair.second + 1);
      }
      return ans;
    }
  }
}

int main() {

  ll n;
  cin >> n;

  vector<ll> primes(10000001, 1);

  primes.at(0) = 0;
  primes.at(1) = 0;

  for (ll i = 2; i < 10000001; i++) {
    if (primes.at(i) == 1) {
      for (ll j = 2 * i; j < 10000001; j += i) {
        primes.at(j) = 0;
      }
    }
  }

  vector<ll> primelist;

  for (ll i = 2; i < 10000001; i++) {
    if (primes.at(i) == 1) {
      primelist.pb(i);
    }
  }

  ll answer = 0;

  vector<map<ll, ll>> data(10000001);

  for (ll x : primelist) {
    map<ll, ll> tmp;
    tmp[x] = 1;
    data.at(x) = tmp;
  }

  for (ll i = 1; i <= n; i++) {
    if (i == 1) {
      answer += 1;
    } else if (primes.at(i) == 1) {
      answer += 2 * i;
    } else {
      answer += i * dividers(i, primelist, data);
    }
  }

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

#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;

  long long ans = 0;

  for (int X = 1; X <= N; X++) {
    long long Y = N / X;
    long long G = Y * (Y + 1) * X / 2;
    ans += G;
  }

  cout << ans << endl;

  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;

  long long ans = 0;

  for (int X = 0; X < N; X++) {
    long long Y = N / X;
    long long G = Y * (Y + 1) * X / 2;
    ans += G;
  }

  cout << ans << endl;

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

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
// #include <tchar.h>
// #include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 1e7 + 10;

LL a[N];

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

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

  LL ans = 0;

  for (int i = 1; i <= n; i++)
    ans += a[i] * i;

  cout << ans << endl;
  cin >> n;
}


Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
// #include <tchar.h>
// #include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 4e5 + 10;

LL a[N];

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

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

  LL ans = 0;

  for (LL i = 1; i <= n; i++)
    ans += a[i] * i;

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

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

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

// /*  divisor_num(n)
//     入力：整数 n
//     出力：nの約数の個数
//     計算量：O(√n)
// */
// template <typename T>
// T divisor_num(T N) {
//     map<T, T> pf = prime_factor(N);
//     T ret = 1;
//     for (auto p : pf) {
//         ret *= (p.second + 1);
//     }
//     return ret;
// }

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

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

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

  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i < n + 1; i++) {
    ll m = n / i;
    ans += m * (m + 1) * i / 2;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

/*  divisor_num(n)
    入力：整数 n
    出力：nの約数の個数
    計算量：O(√n)
*/
template <typename T> T divisor_num(T N) {
  map<T, T> pf = prime_factor(N);
  T ret = 1;
  for (auto p : pf) {
    ret *= (p.second + 1);
  }
  return ret;
}

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

#include <bits/stdc++.h>
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fast ios::sync_with_stdio(false);
#define pi 3.14159265358979323846264338327950288419716939937510
#define pb push_back
#define max 10000002
typedef long long ll;
using namespace std;
int main() {

  ll n;
  scanf("%lld", &n);
  ll a[max] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = 1; i * j <= n; j++) {
      a[i * j]++;
    }
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++)
    ans += a[i] * i;

  printf("%lld", ans);

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fast ios::sync_with_stdio(false);
#define pi 3.14159265358979323846264338327950288419716939937510
#define pb push_back
typedef long long ll;
using namespace std;

ll divisor(ll n) {
  ll temp = sqrt(n), cnt = 0;
  for (ll i = 1; i <= temp; i++) {
    if (n % i == 0)
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
  }
  return cnt;
}

int main() {
  fast ll x;
  cin >> x;
  ll ans = 0;
  for (ll i = 1; i <= x; i++) {
    ans += i * divisor(i);
  }
  cout << ans << endl;

  return 0;
}