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

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define mrep(i, n) for (int i = (int)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20)
#define fi first
#define se second
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll modn = 998244353;

int kosuu(int n) {
  int ans = 1;
  vint x(n + 1);
  int num = n;
  for (int i = 2; i <= n; i++) {
    while (num % i == 0) {
      x[i]++;
      num /= i;
    }
  }
  for (int i = 2; i <= n; i++) {
    ans *= (x[i] + 1);
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rrep(i, 1, n) { ans += kosuu(i) * i; }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 10000010

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n, ans, m, k, cnt;

int a[MAXN];

inline void pri(int x) {
  for (rr int i = 1; i <= x; i++)
    for (rr int j = i; j <= x; j += i)
      a[j]++;
}

signed main() {
  n = read();
  pri(10000000);
  for (rr int i = 1; i <= n; i++)
    ans += i * a[i];
  cout << ans;
}
/*
5 4 731
80 150 80 150 1
60 90 120 149
*/

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 10000010

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n, ans, m, k, cnt;

int a[MAXN];

inline int pri(int x) {
  for (rr int i = 1; i <= x; i++)
    for (rr int j = i; j <= x; j += i)
      a[j]++;
}

signed main() {
  n = read();
  pri(10000000);
  for (rr int i = 1; i <= n; i++)
    ans += i * a[i];
  cout << ans;
}
/*
5 4 731
80 150 80 150 1
60 90 120 149
*/
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;
int n;
unsigned long long ans = 0;

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


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
int n;
long long ans = 0;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) {
        ans += i;
      }
    }
  }
  printf("%lld\\n", ans);

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

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

int main() {
  int N;
  cin >> N;
  long long sum = 0;
  for (int div = 1; div <= N; div++) {
    int n = div;
    while (n <= N) {
      sum += n;
      n += div;
    }
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  bool is_prime[N + 1];
  for (int i = 1; i <= N; i++) {
    is_prime[i] = true;
  }
  int max = (int)(sqrt(N) + 1);
  for (int i = 2; i <= max; i++) {
    if (!is_prime[i])
      continue;
    int p = i;
    int k = 2 * p;
    while (k <= N) {
      is_prime[k] = false;
      k += p;
    }
  }
  int p[N + 1];
  int n_p = 0;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      p[++n_p] = i;
    }
  }
  /*for (int i = 1; i <= n_p; i++)
  {
      cout << p[i] << " ";
  }*/
  int f[N + 1];
  for (int K = 1; K <= N; K++) {
    f[K] = 1;
    int K_copy = K;
    for (int i = 1; i <= n_p; i++) {
      int pow = 0;
      int q = p[i];
      while (K_copy % q == 0) {
        K_copy /= q;
        pow++;
      }
      f[K] *= (1 + pow);
      if (K_copy == 1) {
        break;
      }
    }
  }
  long sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += i * f[i];
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;

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

  ll res = 0;
  ll n;
  cin >> n;

  for (ll i = 1; i <= n; i++) {
    ll cnt = n / i;
    ll cur = i * (cnt * (cnt + 1) / 2);
    res += cur;
  }

  cout << res << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;

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

  auto count = [&](ll x) {
    ll res = 1;
    for (ll i = 2; i * i <= x; i++) {
      if (x % i == 0) {
        ll cnt = 0;
        while (x % i == 0) {
          cnt++;
          x /= i;
        }
        res *= (cnt + 1);
      }
    }

    if (x > 1)
      res *= 2;
    return res;
  };

  ll n;
  cin >> n;

  ll res = 0;

  for (ll i = 1; i <= n; i++) {
    res += i * count(i);
  }

  cout << res << endl;

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

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    int m = floor((n + 0.0) / i);
    sum += (long long int)m * (m + 1) * i / 2;
  }
  cout << sum;
}


Error: TLE

Fixed submission:

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

#include "bits/stdc++.h"

using namespace std;

#define int long long
#define endl "\\n"
#define mod 1000000007
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int32_t main() {

  IOS;

  vector<int> v(10000001, 2);
  v[1] = 1;

  for (int i = 2; i <= 1e7; i++) {
    for (int j = 2 * i; j <= 1e7; j += i)
      v[j]++;
  }

  int n;
  cin >> n;

  int ans = 0;

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl "\\n"
#define mod 1000000007
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

  IOS;

  int n, ans = 0;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    int d = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        d++;
        if (i != j * j)
          d++;
      }
    }

    if (i > 1)
      d++;

    ans += i * d;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll, ll>
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)
#define FORR(I, A, B) for (ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v)                                                             \\
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v  x is sorted
#define POSU(x, v)                                                             \\
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
ll gcd_(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd_(b, a % b);
}
ll lcm_(ll a, ll b) {
  ll c = gcd_(a, b);
  return ((a / c) * (b / c) * c);
}
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = ll(1e16) + ll(7);
const ll MOD = 1000000007LL;
#define out(a) cout << fixed << setprecision((a))
// tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a) {
  ll r = 0;
  while (a) {
    a /= 10;
    r++;
  }
  return r;
}

int main() {

  ll N, ans = 0;
  cin >> N;

  FOR(i, 1, N + 1) {
    ans += i * floor((long double)N / i) * floor(1.0 + (long double)N / i) / 2;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll, ll>
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)
#define FORR(I, A, B) for (ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v)                                                             \\
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v  x is sorted
#define POSU(x, v)                                                             \\
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
ll gcd_(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd_(b, a % b);
}
ll lcm_(ll a, ll b) {
  ll c = gcd_(a, b);
  return ((a / c) * (b / c) * c);
}
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = ll(1e16) + ll(7);
const ll MOD = 1000000007LL;
#define out(a) cout << fixed << setprecision((a))
// tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a) {
  ll r = 0;
  while (a) {
    a /= 10;
    r++;
  }
  return r;
}

ll enum_(ll n) { // yakusu
  ll ans = 1;
  ll N = n;
  for (ll i = 2; i * i <= N; ++i) {
    ll k = 1;
    while (n % i == 0 && n != 1) {
      k++;
      n /= i;
    }
    ans *= k;
  }
  if (n != 1)
    ans *= 2;
  return ans;
}

int main() {

  ll N, ans = 1;
  cin >> N;

  FOR(i, 2, N + 1) { ans += i * enum_(i); }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> fu(n, 0);
  auto func = [&](ll x) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; i * i <= x; ++i) {
      if (x % i != 0)
        continue;
      ll ex = 0;

      while (x % i == 0) {
        ++ex;
        x /= i;
      }
      res.push_back({i, ex});
    }
    if (x != 1)
      res.push_back({x, 1});
    return res;
  };
  ll ans = 0;
  vector<pair<ll, ll>> tmp;
  for (ll i = 1; i <= n; i++) {
    // cout << "i: " << i << endl;
    tmp = func(i);
    ll a = 1;
    for (auto p : tmp) {
      a *= p.second + 1;
      // cout << "second: " << p.second << endl;
    }
    ans += i * a;
    // cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define N 10000000
using namespace std;
long long int NOD[10000001];
void generateNOD() {
  long long int i, j;
  for (i = 1; i <= N; i++) {
    for (j = i; j <= N; j += i) {
      NOD[j] += 1;
    }
  }
}
int main() {
  long long int i, n, c = 0;
  generateNOD();
  cin >> n;
  for (i = 1; i <= n; i++) {
    c += i * NOD[i];
  }
  cout << c << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int countDivisors(long long int n) {
  long long int i, j, cnt = 0;
  for (i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      j = n / i;
      cnt++;
      if (i != j)
        cnt++;
    }
  }
  return cnt;
}

int main() {
  long long int a, b, c = 0, i;
  cin >> a;
  for (i = 1; i <= a; i++) {
    b = i * countDivisors(i);
    c += b;
  }
  cout << c << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define hi cout << "hi"
#define ll long long
#define all(c) c.begin(), c.end()
#define mod 1000000007
#define pb push_back
#define pb2 pop_back
#define ff first
#define ss second
#define debug(x) cout << #x << " : " << x << "\\n";
#define debug2(x, y)                                                           \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\n";
#define IO                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);
const char nl = '\\n';
ll cnt[10000001];
int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 0; (j += i) <= n;) {
      ++cnt[j];
    }
  }
  for (ll i = 1; i <= n; i++) {
    ans += (i * cnt[i]);
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define hi cout << "hi"
#define ll long long
#define all(c) c.begin(), c.end()
#define mod 1000000007
#define pb push_back
#define pb2 pop_back
#define ff first
#define ss second
#define debug(x) cout << #x << " : " << x << "\\n";
#define debug2(x, y)                                                           \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\n";
#define IO                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);
const char nl = '\\n';
ll primefactors(ll n) {
  ll two = 0, ans = 1;
  if (n % 2 == 0) {
    while (n % 2 == 0) {
      two++;
      n /= 2;
    }
  }
  if (two > 0)
    ans = two + 1;
  for (ll i = 3; i <= sqrt(n); i += 2) {
    ll temp = 0;
    while (n % i == 0) {
      n /= i;
      temp++;
    }
    if (temp > 0)
      ans *= (temp + 1);
  }
  if (n > 2)
    ans *= 2;
  return ans;
}
int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ans += (i * primefactors(i));
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll s = 0;
  vector<ll> a(n);
  rep(i, n) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  rep(i, n) { s += a[i] * i; }
  cout << s << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll s = 0;
  vector<ll> a(n);
  rep(i, n / 2) {
    rep(j, n) {
      if (i * j <= n) {
        ll x = i * j;
        a[x]++;
      }
    }
  }
  rep(i, n) { s += a[i] * i; }
  cout << s << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7, INF = mod * mod * 3; // M_PI
#define rep(i, N) for (ll i = 0; i < (N); i++)
#define rep1(i, N) for (ll i = 1; i < (N); i++)
#define pb push_back

ll N;
ll ans;

int main() {

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

  cin >> N;
  rep1(i, N + 1) ans += i * (N / i) * (N / i + 1);
  cout << ans / 2 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7, INF = mod * mod * 3; // M_PI
#define rep(i, N) for (ll i = 0; i < (N); i++)
#define rep1(i, N) for (ll i = 1; i < (N); i++)
#define pb push_back

ll N;
ll dv[10000005];
ll ans;

int main() {

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

  cin >> N;
  rep1(i, N + 1) {
    for (ll k = 1; k <= sqrt(i); k++) {
      if (i % k == 0) {
        dv[i]++;
        if (k != i / k)
          dv[i]++;
      }
    }
  }
  rep1(i, N + 1) ans += i * dv[i];
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9 + 7;
constexpr lint mod2 = 998244353;

int main() {
  int n;
  cin >> n;
  long a = 0;
  rep(i, n) {
    long t = n / (i + 1), u = (t + 1) * t / 2;
    a += (i + 1) * u;
  }
  cout << a << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9 + 7;
constexpr lint mod2 = 998244353;

int main() {
  int n;
  cin >> n;
  long ans = 0;
  v1li v(n, 1);
  rep(i, n - 1) {
    if (i < 2)
      v[i + 1] = (i + 2) * 2;
    if (i == 2)
      v[i + 1] = 12;
    else {
      long tmp = i + 2, a = i + 2;
      for (int j = 2; j <= sqrt(tmp); ++j) {
        if (tmp % j == 0) {
          int b = 1;
          while (a % j == 0) {
            a /= j;
            ++b;
          }
          if (a == 1)
            v[i + 1] = tmp * b;
          else
            v[i + 1] = v[a - 1] * b * (tmp / a);
          break;
        }
      }
      if (a == tmp)
        v[i + 1] = tmp * 2;
    }
  }
  rep(i, n) ans += v[i];
  cout << ans << "\\n";
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

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

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long N = n / i;
    ans += i * (N * (N + 1)) / 2;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

long long yakusu(long long n) {
  long long t = sqrt(n);
  long long ans = 0;
  if (t * t == n) {
    ans--;
  }
  long long res = 0;
  for (int i = 1; i <= t; i++) {
    if (n % i == 0) {
      res++;
    }
  }
  ans += 2 * res;
  return ans;
}

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

  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += i * yakusu(i);
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
ll m;
const ll mod = 1e9 + 7;
const ll maxn = 500005;
ll inv[maxn + 3];
ll fac[maxn + 3];
ll qpow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
inline ll A(ll n, ll m) { return fac[n] * inv[n - m] % mod; }
inline ll C(ll n, ll m) { return A(n, m) * inv[m] % mod; }

int main() {
  // freopen("in.txt","r",stdin);
  cin >> n >> m;
  fac[0] = 1;
  fac[1] = 1;
  for (ll i = 2; i < maxn; i++) {
    fac[i] = i * fac[i - 1];
    fac[i] %= mod;
  }
  inv[0] = 1;
  inv[1] = 1; // inv[0]=1 !!!
  for (ll i = 2; i <= maxn; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  for (ll i = 2; i <= maxn; i++) {
    inv[i] = (inv[i] * inv[i - 1]) % mod;
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll tmp = C(n, i) * A(m - i, n - i);
    tmp %= mod;
    if (i % 2 == 0) {
      ans += tmp;
    } else
      ans -= tmp;
    ans += mod;
    ans %= mod;
  }
  ans *= A(m, n);
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  // cout<<tmp<<endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
ll m;
const ll mod = 1e9 + 7;
const ll maxn = 500005;
ll inv[maxn];
ll fac[maxn];
ll qpow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
inline ll A(ll n, ll m) { return fac[n] * inv[n - m] % mod; }
inline ll C(ll n, ll m) { return A(n, m) * inv[m] % mod; }

int main() {
  // freopen("in.txt","r",stdin);
  cin >> n >> m;
  fac[0] = 1;
  fac[1] = 1;
  for (ll i = 2; i < maxn; i++) {
    fac[i] = i * fac[i - 1];
    fac[i] %= mod;
  }
  inv[0] = 1;
  inv[1] = 1; // inv[0]=1 !!!
  for (ll i = 2; i <= maxn; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  for (ll i = 2; i <= maxn; i++) {
    inv[i] = (inv[i] * inv[i - 1]) % mod;
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll tmp = C(n, i) * A(m - i, n - i);
    tmp %= mod;
    if (i % 2 == 0) {
      ans += tmp;
    } else
      ans -= tmp;
    ans %= mod;
  }
  ans *= A(m, n);
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  // cout<<tmp<<endl;
  return 0;
}