alexjercan/bugnet huggingface dataset:
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define SIZE 10000000
vector<int> prime;
vector<int> factors;
ll sieve[SIZE + 5];

void primeSieve(int n) {
  sieve[0] = sieve[1] = 1;
  prime.push_back(2);
  for (int i = 4; i <= n; i += 2) {
    sieve[i] = 1;
  }
  for (int i = 3; i * i <= n; i += 2) {
    if (sieve[i] == 0) {
      for (int j = i * i; j <= n; j += 2 * i) {
        sieve[j] = 1;
      }
    }
  }
  for (int i = 3; i <= n; i += 2) {
    if (sieve[i] == 0) {
      prime.push_back(i);
    }
  }
}

ll NOD(int n) {
  int sqrtn = sqrt(n);
  ll res = 1;
  for (int i = 0; i < prime.size() && prime[i] <= sqrtn; i++) {
    if (sieve[n] == 0)
      break;
    if (n % prime[i] == 0) {
      int p = 0;
      while (n % prime[i] == 0) {
        n /= prime[i];
        p++;
      }
      sqrtn = sqrt(n);
      p++;
      res *= p;
    }
  }
  if (n != 1) {
    res *= 2;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  primeSieve(SIZE);
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * NOD(i)) % 10000000000000;
  }
  cout << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define SIZE 10000000
vector<int> prime;
vector<int> factors;
long long sieve[SIZE];

void primeSieve(int n) {
  sieve[0] = sieve[1] = 1;
  prime.push_back(2);
  for (int i = 4; i <= n; i += 2) {
    sieve[i] = 1;
  }
  for (int i = 3; i * i <= n; i += 2) {
    if (sieve[i] == 0) {
      for (int j = i * i; j <= n; j += 2 * i) {
        sieve[j] = 1;
      }
    }
  }
  for (int i = 3; i <= n; i += 2) {
    if (sieve[i] == 0) {
      prime.push_back(i);
    }
  }
}

ll NOD(int n) {
  int sqrtn = sqrt(n);
  ll res = 1;
  for (int i = 0; i < prime.size() && prime[i] <= sqrtn; i++) {
    if (sieve[n] == 0)
      break;
    if (n % prime[i] == 0) {
      int p = 0;
      while (n % prime[i] == 0) {
        n /= prime[i];
        p++;
      }
      sqrtn = sqrt(n);
      p++;
      res *= p;
    }
  }
  if (n != 1) {
    res *= 2;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  primeSieve(SIZE);
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * NOD(i)) % 10000000000000;
    /// cout << NOD(i) << " ";
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <map>
#define For(i, x, y) for (int i = (x); i <= (y); i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
/*
int num(int n)
{
    int x=n,tmp;
    if(n==1)return 1;
    int cnt=2;
    for(int i=2; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            if(i==sqrt(n)&&n/i==i)cnt++;
            else cnt+=2;
        }
    }
    return cnt;
}
*/
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, m, ans = 0;
  cin >> n;
  For(i, 1, n) {
    m = n / i;
    ans += (m + 1) * m * i / 2;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#define For(i, x, y) for (int i = (x); i <= (y); i++)
using namespace std;
typedef unsigned long long ull;
// map<ull,int>ma;
int num(int n) {
  int x = n, tmp;
  if (n == 1)
    return 1;
  int cnt = 2;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i == sqrt(n) && n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ull tmp = 0;
  ull n;
  cin >> n;
  For(i, 1, n) tmp += (ull)num(i) * i;
  cout << tmp << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define LL long long
LL ans, b;
int n, prime[2000], not_prime[10010], tot;
void linear_shaker(int x) {
  int i, j;
  for (i = 2; i <= x; i++) {
    if (!not_prime[i])
      prime[++tot] = i;
    for (j = 1; prime[j] * i <= x; j++) {
      not_prime[prime[j] * i] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
int main() {
  int i, n, cnt, x, j;
  linear_shaker(10000);
  ans = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    x = i, b = 1;
    for (j = 1; prime[j] * prime[j] <= x; j++) {
      cnt = 0;
      if (x % prime[j] == 0) {
        while (x % prime[j] == 0)
          x /= prime[j], cnt++;
        b *= (cnt + 1);
      }
    }
    if (x > 1)
      b *= 2;
    ans += b * i;
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#define LL long long
LL ans, b;
int n, prime[1000], not_prime[10010], tot;
void linear_shaker(int x) {
  int i, j;
  for (i = 2; i <= x; i++) {
    if (!not_prime[i])
      prime[++tot] = i;
    for (j = 1; prime[j] * i <= x; j++) {
      not_prime[prime[j] * i] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
int main() {
  int i, n, cnt, x, j;
  linear_shaker(10000);
  ans = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    x = i, b = 1;
    for (j = 1; prime[j] * prime[j] <= x; j++) {
      cnt = 0;
      if (x % prime[j] == 0) {
        while (x % prime[j] == 0)
          x /= prime[j], cnt++;
        b *= (cnt + 1);
      }
    }
    if (x > 1)
      b *= 2;
    ans += i * b;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) { // 階乗
  if (i == 0)
    return 1;
  return (factorial(i - 1)) * i;
}
ll g(ll g) { return (g * (g + 1) / 2); }
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep1(i, n) ans += i * g(n / i);
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) { // 階乗
  if (i == 0)
    return 1;
  return (factorial(i - 1)) * i;
}
int number_divisor(ll n) {
  int count = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0)
      i *i == n ? count++ : count += 2;
  }
  return count;
}

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

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

long long ans;
int n;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long LL;
LL ans;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i % j == 0)
        ans += i;
  cout << ans;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
signed main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += (i * (n / i) * (n / i + 1) / 2);
  cout << ans;
  re 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int v[10000015];
bool isp(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0)
      re 0;
  re 1;
}
void f_pri() {
  for (int i = 2; i < 10000015; i++)
    if (isp(i))
      for (int j = i; j < 10000015; j += i) {
        int num = j, t = 0;
        while (num % i == 0) {
          t++;
          num /= i;
        }
        v[j] *= t + 1; // cout<<j<<" "<<i<<" "<<t<<"\\n";
      }
}
signed main() {
  f_pri();
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ans += i * v[i];
  }
  cout << ans;
  re 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

long long ans;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    long long tmp = n / i;
    ans += (1 + tmp) * tmp / 2 * i;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

long long ans[10000010];

int main() {
  int n;
  scanf("%d", &n);
  // 约数个数公式
  for (int i = 1; i <= n; i++) {
    int t = i;
    ans[i]++;
    for (int j = 2; j * j <= n; j++) {
      if (t == 1)
        break;
      long long cnt = 0;
      while (t % j == 0) {
        cnt++;
        t /= j;
      }
      ans[i] *= cnt + 1;
    }
    if (t != 1)
      ans[i] *= 2;
    ans[i] *= i;
    ans[i] += ans[i - 1];
  }
  printf("%lld\\n", ans[n]);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

ll arr[10000002];

int run_test() {
  int n;
  cin >> n;
  cout << arr[n] << "\\n";
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  for (int i = 1; i <= 10000000; i++) {
    for (int j = i; j <= 10000000; j += i) {
      arr[j]++;
    }
  }
  ll sum = 0, count = 1;
  for (int i = 1; i <= 10000000; i++) {
    sum += arr[i] * (count++);
    arr[i] = sum;
  }

  while (t--) {
    run_test();
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

ll arr[1000002];

int run_test() {
  int n;
  cin >> n;
  cout << arr[n] << "\\n";
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  for (int i = 1; i <= 1000000; i++) {
    for (int j = i; j <= 1000000; j += i) {
      arr[j]++;
    }
  }
  ll sum = 0, count = 1;
  for (int i = 1; i <= 1000000; i++) {
    sum += arr[i] * (count++);
    arr[i] = sum;
  }

  while (t--) {
    run_test();
  }
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll N, K;
ll m;
string S, T;
ll d;
ll ans;
ll A[10000001];
ll B[10000001];
vector<ll> so;

int main() {
  for (int i = 2; i < 4000; i++) {
    bool found = false;
    for (int j = 0; j < so.size(); j++) {
      if (i % so[j] == 0) {
        found = true;
      }
    }
    if (!found) {
      so.push_back(i);
    }
  }
  cin >> N;
  for (ll i = 1; i <= N; i++) {
    A[i] = 1;
    B[i] = i;
  }
  for (int j = 0; j < 550; j++) {
    ll i = 0;
    i += so[j];
    while (i <= N) {
      ll k = 0;
      while (B[i] % so[j] == 0) {
        B[i] /= so[j];
        k++;
      }
      A[i] *= (k + 1);
      i += so[j];
    }
  }
  for (ll i = 1; i <= N; i++) {
    if (B[i] != 1) {
      A[i] *= 2;
    }
    ans += i * A[i];
  }

  cout << ans << endl;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll N, K;
ll m;
string S, T;
ll d;
ll ans;
ll M = 1000000007;
ll A[10000001];
ll B[200001];
vector<ll> so;
vector<ll> fac(5000001);  // n!(mod M)
vector<ll> ifac(5000001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分

// ll mpow(ll x, ll n){ //x^n(mod M)
// ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }
//
// ll comb(ll a, ll b){ //aCbをmod計算
//     if(a == 0 && b == 0)return 1;
//     if(a < b || a < 0)return 0;
//     ll tmp = ifac[a-b]* ifac[b] % M;
//     return tmp * fac[a] % M;
// }
int main() {
  for (int i = 2; i < 4000; i++) {
    bool found = false;
    for (int j = 0; j < so.size(); j++) {
      if (i % so[j] == 0) {
        found = true;
      }
    }
    if (!found) {
      so.push_back(i);
    }
  }
  cin >> N;
  for (int i = 1; i <= N; i++) {
    A[i] = 1;
  }
  for (int j = 0; j < 550; j++) {
    int i = 0;
    while (i <= N) {
      i += so[j];
      int k = 0;
      ll ii = i;
      while (ii % so[j] == 0) {
        ii /= so[j];
        k++;
      }
      A[i] *= (k + 1);
    }
  }
  for (int i = 1; i <= N; i++) {
    ans += i * A[i];
  }

  //    for(int i=1;i<=N;i++){
  //        ll ii = i;
  //        ll ansa=1;
  //        for(int j=0;j<so.size();j++){
  //            if(ii<so[j]){
  //                break;
  //            }
  //            int a=0;
  //            while(ii%so[j]==0){
  //                ii/=so[j];
  //                a++;
  //            }
  //            ansa *= (a+1);
  //        }
  //        ans += i*ansa;
  //    }

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

#include <algorithm>
#include <iostream>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int)1e9 + 7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n + 1] = {0};
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i; j < n + 1; j += i) {
        arr[j]++;
      }
    }
    for (int i = 1; i <= n; i++)
      ans += (long long)i * arr[i];

    cout << ans;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int)1e9 + 7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) {
  for (int i = 2; i <= n; i++)
    prime[i] = true;
  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;
  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      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;
      primesquare[p * p] = true;
      j++;
    }
  }
}
int countDivisors(int n) {
  if (n == 1)
    return 1;
  bool prime[n + 1], primesquare[n * n + 1];
  int a[n]; // for storing primes upto n
  SieveOfEratosthenes(n, prime, primesquare, a);
  int ans = 1;
  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
    }
    ans = ans * cnt;
  }
  if (prime[n])
    ans = ans * 2;
  else if (primesquare[n])
    ans = ans * 3;
  else if (n != 1)
    ans = ans * 4;

  return ans; // Total divisors
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    // cout << divCount(n) << endl;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
      ans += (i * countDivisors(i));
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define st first
#define sc second
#define arr array

using namespace std;
const ll mod = 1e9 + 7;
const int e = 1e7 + 79;
const int maxn = 10 * 1e6 + 69;

ll dp[e];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<ll> ans;
  int t;
  cin >> t;
  for (int i = 2; i * i <= e; i++) {
    if (dp[i] == 0) {
      ans.pb(i);
      for (int j = i * 2; j <= e; j += i) {
        dp[j]++;
      }
    }
  }
  ll answer = 0;
  for (ll i = 1; i <= t; i++) {
    ll n = i;
    int kq = 1;
    dp[1] = 1;
    for (auto j : ans) {
      // cout << j <<" ";
      if (j * j * j > n || dp[n] == 0)
        break;
      int cnt = 1;
      while (n % j == 0) {
        n /= j;
        cnt++;
      }
      kq *= cnt;
    }
    int cur = sqrt(n);
    if (!dp[n]) {
      kq *= 2;
    } else if (cur * cur == n && !dp[cur]) {
      kq *= 3;
    } else if (n != 1) {
      kq *= 4;
    }
    answer += i * kq;
    // cout << kq <<" ";
  }
  cout << answer;
}
/*
8 1 2
-1 3 -2 5 3 -5 2 2
*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define st first
#define sc second
#define arr array

using namespace std;
const ll mod = 1e9 + 7;
const int e = 1e7 + 79;
const int maxn = 1e6 + 69;

ll dp[e];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<ll> ans;
  for (int i = 2; i * i <= e; i++) {
    if (dp[i] == 0) {
      ans.pb(i);
      for (int j = i * 2; j <= e; j += i) {
        dp[j]++;
      }
    }
  }
  int t;
  cin >> t;
  ll answer = 0;
  for (ll i = 1; i <= t; i++) {
    ll n = i;
    int kq = 1;
    dp[1] = 1;
    for (auto j : ans) {
      // cout << j <<" ";
      if (j * j * j > n)
        break;
      int cnt = 1;
      while (n % j == 0) {
        n /= j;
        cnt++;
      }
      kq *= cnt;
    }
    int cur = sqrt(n);
    if (!dp[n]) {
      kq *= 2;
    } else if (cur * cur == n && !dp[cur]) {
      kq *= 3;
    } else if (n != 1) {
      kq *= 4;
    }
    answer += i * kq;
    // cout << n*kq <<"\\n";
  }
  cout << answer;
}
/*
8 1 2
-1 3 -2 5 3 -5 2 2
*/
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll a, sum = 0;
  cin >> a;

  for (ll i = 1; i <= a; i++) {
    for (ll j = i; j <= a; j = j + i) {
      sum = sum + j;
    }
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define sz 10000000

vector<ll> v;
bool arr[10000000 + 10];

int factorization(ll j) {
  ll ans = 1;

  for (ll i = 0; i < v.size(); i++) {
    ll cnt = 1;
    ll x = v[i];
    if (x * x > j)
      break;
    while (j % x == 0) {
      cnt++;
      j /= x;
    }
    ans = ans * cnt;
  }

  if (j > 1) {
    ans = ans * 2;
  }

  return ans;
}

void sieve() {
  v.push_back(2);
  for (ll i = 4; i <= sz; i += 2)
    arr[i] = 1;
  for (ll i = 3; i <= sz; i += 2) {
    if (!arr[i]) {
      v.push_back(i);
      if (i * i <= sz) {
        for (ll j = i * i; j <= sz; j += i + i) {
          arr[j] = 1;
        }
      }
    }
  }
}

int main() {
  sieve();

  ll n, ans = 1, res;
  cin >> n;

  for (ll i = 2; i <= n; i++) {
    res = factorization(i);
    ans = ans + (res * i);
  }

  cout << ans << endl;

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

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

#define int long long
#define endl "\\n"
#define pb push_back
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);

const int N = 2e5 + 5;
const double pi = 3.141592653589793238;

int32_t main() {
  IOS;
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int num = n / i;
    cnt += i * (num + 1) * num / 2;
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

#define int long long
#define endl "\\n"
#define pb push_back
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);

const int N = 2e5 + 5;
const double pi = 3.141592653589793238;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  ll n;
  cin >> n;
  vector<ll> a(n + 1, 0);

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  ll n;
  cin >> n;
  ll ans = 0, cnt;
  for (ll i = 1; i <= n; ++i) {
    cnt = 1;
    for (ll d = 1; d <= (i >> 1); ++d) {
      cnt += (i % d == 0);
    }
    //        cnt += (i^1 ? 1 : 0);
    cnt *= i;
    ans += cnt;
  }
  cout << ans;

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

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    int d = n / i;
    ans += ((d * (d + 1)) / 2) * i;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

const int mxN = 10000000;
vector<int> p(mxN, 0);

int seive(int n) {
  int cnt = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = i; j < n + 1; j += i) {
      p[j]++;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    cnt += i * p[i];
  }
  cout << cnt;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  seive(n);
  return 0;
}