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

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout << s, 0
#define rcc(s) cout << s, exit(0)
using namespace std;

const int nmax = 10000005;

int n, lp[nmax], divi[nmax];
vector<int> pr;

int32_t main() {
  // ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  for (int i = 2; i < nmax; ++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] < nmax;
         ++j)
      lp[i * pr[j]] = pr[j];
  }
  cin >> n;
  int ans = 1;
  divi[1] = 1;
  for (int i = 2; i <= n; i++) {
    int cnt = 0;
    int num = i;
    while (num % lp[i] == 0) {
      cnt++;
      num /= lp[i];
    }
    divi[i] = divi[num] * (cnt + 1);
    ans += divi[i] * i;
  }
  rc(ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout << s, 0
#define rcc(s) cout << s, exit(0)
using namespace std;

const int nmax = 10000005;

int n, ans;
vector<int> ciur[nmax];
bitset<nmax> viz;

int32_t main() {
  //  ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n;
  for (int i = 2; i < nmax; i++) {
    if (viz[i] == 0) {
      for (int j = i; j < nmax; j += i) {
        viz[j] = 1;
        ciur[j].push_back(i);
      }
    }
  }
  ans = 1;
  for (int i = 2; i <= n; i++) {
    int curr = 1;
    for (auto it : ciur[i]) {
      int cnt = 0;
      int num = i;
      while (num % it == 0) {
        cnt++;
        num /= it;
      }
      curr *= (cnt + 1);
    }
    ans += i * curr;
  }
  rc(ans);
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<ll> prime;
  bool a[n + 1];
  rep(i, n + 1) { a[i] = true; }
  for (ll i = 2; i <= n; i++) {
    if (a[i]) {
      for (ll j = 2 * i; j <= n; j += i) {
        a[j] = false;
      }
      prime.push_back(i);
    }
  }
  /*rep(i,prime.size()){
      cout << prime[i] << endl;
  }*/
  // cout << 1%prime[0] << endl;
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    // cout << i << endl;
    ll num = 1;
    for (ll j = 0; j < prime.size(); j++) {
      ll a = 1;
      ll ii = i;
      while (ii % prime[j] == 0) {
        ii /= prime[j];
        a++;
      }
      num *= a;
      if (ii == 1) {
        break;
      }
    }
    ans += num * i;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  double n;
  cin >> n;
  ll res = 0;
  for (double k = 1; k <= n; k++)
    res += (((double)k / 2.0F) * floor(n / (double)k) *
            floor(1.0F + (n / (double)k)));
  cout << res << endl;
}

Error: TLE

Fixed submission:

// Author : Vipul Sharma

// LIBRARIES
#include <bits/stdc++.h>

// MACROS
#define ll long long int
#define ld long double
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rev(i, b, a) for (ll i = b - 1; i >= a; i--)
#define eqrep(i, a, b) for (ll i = 1; i <= b; i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define w(t) while (t--)
#define booster                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define mod 1000000007
#define endl "\\n"
#define INF 0x3f3f3f3f
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\\t" << #y << " : " << y << endl;
#define deb3(x, y, z)                                                          \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\t" << #z << " : "  \\
       << z << endl;
#define deb4(x, y, z, w)                                                       \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\t" << #z << " : "  \\
       << z << "\\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e)                                                    \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f)                                                 \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \\
       << #f << ": " << f << endl;

using namespace std;
long long cost = 1e18;

ll countDivisors(ll n) {
  ll cnt = 0;
  for (ll i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal,
      // count only one
      if (n / i == i)
        cnt++;

      else // Otherwise count both
        cnt = cnt + 2;
    }
  }
  return cnt;
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  booster;
  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    res += (i * countDivisors(i));
  }
  cout << res << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, s = 0, n;
  cin >> n;
  long long a[n + 1];
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j = j + i) {
      s = s + j;
    }
  }
  cout << s;
  return 0;
}


Error: TLE

Fixed submission:

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

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

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

#define ll long long
#define ar array

const int mxN = 1e7;
int n, c[mxN + 1];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; (j += i) <= n;)
      ++c[j];
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += (ll)i * c[i];
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
#include <bits/stdc++.h>
using namespace std;

void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) {
  // 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.
  for (int i = 2; i <= n; i++)
    prime[i] = true;

  // Create a boolean array "primesquare[0..n*n+1]"
  // and initialize all entries it as false. A value
  // in squareprime[i] will finally be true if i is
  // square of prime, else false.
  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

  // 1 is not a prime number
  prime[1] = false;

  for (int 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
      for (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (prime[p]) {
      // Storing primes in an array
      a[j] = p;

      // Update value in primesquare[p*p],
      // if p is prime.
      primesquare[p * p] = true;
      j++;
    }
  }
}

// Function to count divisors
int countDivisors(int n) {
  // If number is 1, then it will have only 1
  // as a factor. So, total factors will be 1.
  if (n == 1)
    return 1;

  bool prime[n + 1], primesquare[n * n + 1];

  int a[n]; // for storing primes upto n

  // Calling SieveOfEratosthenes to store prime
  // factors of n and to store square of prime
  // factors of n
  SieveOfEratosthenes(n, prime, primesquare, a);

  // ans will contain total number of distinct
  // divisors
  int ans = 1;

  // Loop for counting factors of n
  for (int i = 0;; i++) {
    // a[i] is not less than cube root n
    if (a[i] * a[i] * a[i] > n)
      break;

    // Calculating power of a[i] in n.
    int cnt = 1;          // cnt is power of prime a[i] in n.
    while (n % a[i] == 0) // if a[i] is a factor of n
    {
      n = n / a[i];
      cnt = cnt + 1; // incrementing power
    }

    // Calculating number of divisors
    // If n = a^p * b^q then total divisors of n
    // are (p+1)*(q+1)
    ans = ans * cnt;
  }

  // if a[i] is greater than cube root of n

  // First case
  if (prime[n])
    ans = ans * 2;

  // Second case
  else if (primesquare[n])
    ans = ans * 3;

  // Third casse
  else if (n != 1)
    ans = ans * 4;

  return ans; // Total divisors
}

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

// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;
ll INF = 1e10;

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


Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

ll prime_factorize(ll n) {
  vector<ll> res;
  ll ans = 1;
  for (ll p = 2; p <= sqrt(n); p++) {
    ll cnt = 0;
    if (n % p != 0)
      continue;
    while (n % p == 0) {
      n /= p;
      cnt++;
    }
    ans *= cnt + 1;
  }
  if (n != 1)
    ans *= 2;
  return ans;
}

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

#include <algorithm>
#include <bits/stdc++.h>
#include <set>
#define ll long long
#include <string.h>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846
using namespace std;
const int MAX = 10000001;

// array to store prime factors
ll int factor[MAX] = {0};

// function to generate all prime factors
// of numbers from 1 to 10^6
void generatePrimeFactors() {
  factor[1] = 1;

  // Initializes all the positions with their value.
  for (ll int i = 2; i < MAX; i++)
    factor[i] = i;

  // Initializes all multiples of 2 with 2
  for (ll int i = 4; i < MAX; i += 2)
    factor[i] = 2;

  // A modified version of Sieve of Eratosthenes to
  // store the smallest prime factor that divides
  // every number.
  for (ll int i = 3; i * i < MAX; i++) {
    // check if it has no prime factor.
    if (factor[i] == i) {
      // Initializes of j starting from i*i
      for (ll int j = i * i; j < MAX; j += i) {
        // if it has no prime factor before, then
        // stores the smallest prime divisor
        if (factor[j] == j)
          factor[j] = i;
      }
    }
  }
}

// function to calculate number of factors
ll int calculateNoOFactors(int n) {
  if (n == 1)
    return 1;

  ll int ans = 1;

  // stores the smallest prime number
  // that divides n
  ll int dup = factor[n];

  // stores the count of number of times
  // a prime number divides n.
  ll int c = 1;

  // reduces to the next number after prime
  // factorization of n
  ll int j = n / factor[n];

  // false when prime factorization is done
  while (j != 1) {
    // if the same prime number is dividing n,
    // then we increase the count
    if (factor[j] == dup)
      c += 1;

    /* if its a new prime factor that is factorizing n,
       then we again set c=1 and change dup to the new
       prime factor, and apply the formula explained
       above. */
    else {
      dup = factor[j];
      ans = ans * (c + 1);
      c = 1;
    }

    // prime factorizes a number
    j = j / factor[j];
  }

  // for the last prime factor
  ans = ans * (c + 1);

  return ans;
}

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

  ll int i, j, p, ans = 0;
  for (i = 1; i <= n; i++) {
    ll int p = calculateNoOFactors(i);

    ans += p * i;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <set>
#define ll long long
#include <string.h>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846
using namespace std;
int main() {
  ll int n;
  cin >> n;
  ll int i, j, p, ans = 0;
  for (i = 1; i <= n; i++) {
    p = 1;
    ll int a = i;
    for (j = 2; j * j <= a; j++) {
      ll int c = 0;
      while (a % j == 0) {
        a = a / j;
        c++;
      }
      p = p * (c + 1);
    }
    if (a != 1)
      p = p * 2;

    ans += i * p;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define INF (1LL << 50)
#define MOD 1000000007

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


Error: WA

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int vet[10000];
int main() {
  int n, m, all, sum, s, ii, i, t;
  char str[17] = {'0', '1', '2', '3', '4', '5', '6', '7',
                  '8', '9', 'A', 'B', 'C', 'D', 'E'};
  while (scanf("%d%d", &n, &m) != EOF) {
    if (n == 1) {
      printf("1\\n");
      continue;
    }
    all = n;
    sum = 0;
    for (i = 2; i < all; i++) {
      if (n % i == 0) {
        all =
            n /
            i; // 注意这一步优化，最关键的一步，如果i是n的因数，那么我们直接把i和n/i一起算了，i的上界变成了n/i-1
        // printf("%d %d",i,n/i);
        s = 0;
        ii = i;
        while (ii) {
          t = ii % m;
          s += t * t;
          ii = ii / m;
        }
        ii = n / i;
        while (ii) {
          t = ii % m;
          s += t * t;
          ii = ii / m;
        }
        sum += s;
      }
    }
    s = 0;
    ii = n;
    while (ii) {
      t = ii % m;
      s += t * t;
      ii = ii / m;
    }
    sum += s;
    sum++;
    t = 0;
    while (sum) {
      vet[t++] = sum % m;
      sum = sum / m;
    }
    for (i = t - 1; i >= 0; i--) {
      printf("%c", str[vet[i]]);
    }

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

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

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


Error: TLE

Fixed submission:

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

map<ll, ll> mp;

ll f(ll k) {
  if (k == 1)
    return 1;
  if (k == 2)
    return 2;
  ll cal = 1;
  ll tmp = k;
  for (ll i = 2; i * i <= k; ++i) {
    ll ex = 0;
    if (k % i == 0) {
      while (k % i == 0) {
        ex++;
        k /= i;
      }
    }
    if (mp[k] > 0) {
      cal *= (ex + 1);
      cal *= mp[k];
      k = 1;
      break;
    }
    cal *= (ex + 1);
  }
  if (k != 1)
    cal *= 2;
  mp[tmp] = cal;
  return cal;
}

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

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

int main() {
  ll n;
  cin >> n;
  // map<ll,int> mp;
  vector<ll> mp(n + 1, 0);
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j = j + i) {
      mp[j]++;
    }
    ans += i * mp[i];
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  lll ii, jj, kk;
  vector<int> ret;

  lll n;

  cin >> n;
  lll ans;

  ans = 0;

  // for(jj=1;jj<=n;jj++){
  //   for(ii=1;ii<=n;ii++){
  //     if(ii % jj == 0){
  //       ans += ii;
  //     }
  //   }
  // }

  ans = 0;

  lll k, x;
  lll sum;

  for (ii = 1; ii <= n; ii++) {

    k = ii;
    x = n / ii;

    sum = k * (x * (x + 1) / 2);

    ans += sum;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

lll getAliquotNum(lll n) {

  int num = 0;
  lll ii;

  for (ii = 1; ii <= n / 2; ii++) {
    if (n % ii == 0) {
      num++;
    }
  }

  num += 1;

  return num;
}

vector<int> prime;

void getPrime(int n) {
  int ii, jj;

  for (ii = n; ii <= n; ii++) {

    bool flg = true;

    // for(jj=2 ;jj<=sqrt(ii); jj++){
    //   //cout << "jj:" << jj << "ii:" << ii <<endl;
    //   if(ii % jj == 0){
    //     flg = false;
    //   }
    //
    // }

    // 最初は取得した素数から判定
    for (int p : prime) {
      if (ii % p == 0) {
        flg = false;
        break;
      }
    }

    if (flg && prime.size() != 0) {
      for (jj = prime[prime.size() - 1]; jj <= sqrt(n); jj++) {
        if (ii % jj == 0) {
          flg = false;
          break;
        }
      }
    }
    if (flg) {
      prime.push_back(ii);
    }
  }
}

bool isPrime(int n) {

  for (int ii = 2; ii * ii <= n; ii++) {
    if (n % ii == 0) {
      return false;
    }
  }

  return n != 1;
}

vector<int> divisor(int n) {

  vector<int> res;

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

    if (n % ii == 0) {

      res.push_back(ii);

      if (ii != n / ii) {
        res.push_back(n / ii);
      }
    }
  }

  return res;
}

int main() {

  lll ii, jj, kk;
  vector<int> ret;

  lll n;

  cin >> n;

  lll sum;

  sum = 0;

  int num = 0;

  // 素数を求める
  // getPrime(n);

  // if(isPrime(n)){
  //   cout << "prime" << endl;
  // }
  // else{
  //   cout << "not prime" << endl;
  // }

  // for(ii=0;ii<prime.size();ii++){
  //   cout << prime[ii] << endl;
  // }
  // for(ii=1;ii<=n;ii++){
  //
  //   num  = getAliquotNum(ii);
  //   sum += ii*getAliquotNum(ii);
  //   //cout << ii << ":" << num << endl;
  //
  // }

  vector<int> div;

  for (ii = 1; ii <= n; ii++) {

    div = divisor(ii);

    // cout << div.size() << endl;

    sum += ii * div.size();
  }

  cout << sum << 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)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    ans += i * g(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)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int yakusucnt(int n) {
  int ans = 1;
  vector<int> x(n + 1);
  int num = n;

  for (int i = 2; i <= n; i++) {
    while (num % i == 0) {
      x.at(i)++;
      num /= i;
    }
    ans *= x.at(i) + 1;
  }
  return ans;
}

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

#include <bits/stdc++.h>
using namespace std;
long long int n, f[10000005], cnt, ans, s;
int main() {
  int i, j, k;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i) {
      f[j]++;
    }
  }
  for (i = 1; i <= n; i++)
    ans += i * f[i];
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int f[10000010], n, ans;
long long int ff(long long int n) {
  int s = 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int a = 0;
      while (n % i == 0) {
        n /= i;
        a++;
      }
      s = s * (a + 1);
    }
  }
  if (n > 1)
    s *= 2;
  return s;
}
int main() {
  cin >> n;
  int i, j, k;
  for (i = 1; i <= n; i++) {
    f[i] = ff(i);
  }
  for (i = 1; i <= n; i++) {
    ans += i * f[i];
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[6] = {0, 1, 0, -1, 1, -1};
const int vy[6] = {1, 0, -1, 0, 1, 1};

ll f(ll a) {
  ll rep = 0;
  for (ll i = 1; i <= a / 2; ++i) {
    if (a % i == 0) {
      rep++;
    }
  }
  return rep + 1;
}

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

  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> dp(20000000, 2);
  dp[0] = 0;
  dp[1] = 1;
  rep(i, n / 2 + 1) {
    if (i == 0 || i == 1)
      continue;
    for (ll j = i + i; j <= n; j += i) {
      dp[j]++;
    }
  }
  rep(i, n + 1) { ans += i * dp[i]; }
  cout << ans << endl;

  cout << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[6] = {0, 1, 0, -1, 1, -1};
const int vy[6] = {1, 0, -1, 0, 1, 1};

ll f(ll a) {
  ll rep = 0;
  for (ll i = 1; i <= a / 2; ++i) {
    if (a % i == 0) {
      rep++;
    }
  }
  return rep + 1;
}

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

  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> dp(200000000, 2);
  dp[0] = 0;
  dp[1] = 1;
  rep(i, n / 2 + 1) {
    if (i == 0 || i == 1)
      continue;
    for (ll j = i + i; j <= n; j += i) {
      dp[j]++;
    }
  }
  rep(i, n + 1) { ans += i * dp[i]; }
  cout << ans << endl;

  cout << endl;
  return 0;
}