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

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
  ll n, i, sum = 0;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    ll x = (n / i);
    sum = sum + i * ((x * (x + 1)) / 2);
  }
  cout << sum << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
#define mpi map<ll, ll>
#define si set<ll>
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define reP(i, a, n) for (ll i = a; i <= n; i++)
#define YES cout << "YES\\n";
#define NO cout << "NO\\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define st string
#define sz size()
#define case(i, n) Case << " " << i << ": " << n << endl;
#define tc                                                                     \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
int main() {
  ll n, cnt = 0;
  cin >> n;
  mpi check;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      check[j]++;
    }
  }
  for (ll i = 1; i <= n; i++)
    cnt += (i * check[i]);
  cout << cnt << endl;

  check.clear();
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define st string
#define con continue
#define br break
#define rt return 0
#define fr first
#define sec second
using namespace std;
int main() {
  // ll tc; cin>>tc; while(tc--){
  ll n, m, mn = INT_MAX, i, x, j, a = 0, t, k, b = -1, mx = -1, cnt = 0, c = 0;
  st s, str;
  char strn;
  cin >> n; // a=n; n-=1;
  // ll ara[n+1],bra[n+1],taj[n+1];

  // for(i=1;i<=n;i++) cin>>ara[i];
  for (i = 1; i <= n; i++) {
    a = 0;
    for (j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (i / j == j)
          ++a;

        else
          a += 2;
        ;
      }
    }
    // cout<<a<<" ";
    c += (a * i);
  }

  cout << c << endl;

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

#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define inf 0x3f3f3f3f
#define db double
using namespace std;
const int maxn = 1e7 + 10;
int d[2][6], cnt1 = 0, cnt2 = 0;
ll a[maxn];
int main() {
  a[0] = 0;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    a[i] = a[i - 1] + i;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int t = n / i;
    ans += (ll)i * a[t];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
unsigned long long f(unsigned int a) {
  int count = 0;
  for (int i = 1; i <= a; i++) {
    if (a % i == 0) {
      count++;
    }
  }
  return count;
}
int main() {
  unsigned int n;
  unsigned long long jumlah = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    jumlah += i * f(i);
  }
  cout << jumlah << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error


// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e7 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

int n;
ll a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll res = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  for (int i = 2; i <= n; ++i) {
    res += (a[i] + 1) * i;
  }
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:


// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

int n;
ll a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll res = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  for (int i = 2; i <= n; ++i) {
    res += (a[i] + 1) * i;
  }
  cout << res << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
struct num {
  long long aaa, bbb, ccc;
};
vector<num> vec;
vector<long long> vec2;
long long check[10000005] = {0};
long long prime[10000005] = {0};
int main() {
  int pos = 0;
  int flag;
  for (int i = 2; i < 10000002; i++) {
    if (!check[i])
      prime[pos++] = i;

    for (int j = 0; j < pos && i * prime[j] < 10000002; j++) {
      check[i * prime[j]] = prime[j];
      if (i % prime[j] == 0)
        break;
    }
  }
  long long n;
  cin >> n;
  long long ss = 0;
  for (long long i = 1; i <= n; i++) {
    if (i == 1) {
      ss += 1;
      continue;
    }
    int q = i;
    int p = 1;
    if (check[i] == 0) {
      num h;
      h.aaa = 1;
      h.bbb = i;
      h.ccc = 1;
      vec.push_back(h);
    } else {
      if (vec[q / check[i] - 2].bbb == check[i]) {
        num h;
        h.aaa = vec[q / check[i] - 2].aaa;
        h.bbb = vec[q / check[i] - 2].bbb;
        h.ccc = vec[q / check[i] - 2].ccc + 1;
        vec.push_back(h);
      } else {
        num h;
        h.aaa = vec[q / check[i] - 2].aaa * (vec[q / check[i] - 2].ccc + 1);
        h.bbb = check[i];
        h.ccc = 1;
        vec.push_back(h);
      }
    }
    ss += vec[i - 2].aaa * i * (vec[i - 2].ccc + 1);
  }
  cout << ss << endl;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define pb push_back
const int mod = 1e9 + 7, size = 1e6 + 1;

int divCount(int n) {
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (int p = 2; p * p < n; p++)
    if (hash[p] == true)
      for (int i = p * 2; i < n; i += p)
        hash[i] = false;

  int total = 1;
  for (int p = 2; p <= n; p++) {
    if (hash[p]) {
      int count = 0;
      if (n % p == 0) {
        while (n % p == 0) {
          n = n / p;
          count++;
        }
        total = total * (count + 1);
      }
    }
  }
  return total;
}

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

  ll int n, count = 0;
  cin >> n;

  vector<ll int> v(10000002);

  for (int i = 1; i <= n; ++i)
    v[i] = (i * divCount(i)), count += v[i];

  cout << count << "\\n";
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define rREP(i, m, n) for (int(i) = (n)-1; (i) >= (m); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  int N;
  cin >> N;
  vector<ll> vec(N + 1, 0);
  rep(i, 1, N + 1) {
    for (int j = i; j <= N; j += i) {
      vec[j]++;
    }
  }
  ll ans = 0;
  rep(i, 1, N + 1) { ans += i * vec[i]; }
  cout << ans << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define rREP(i, m, n) for (int(i) = (n)-1; (i) >= (m); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  int N;
  cin >> N;
  vector<unordered_map<int, int>> vec(N + 1);
  vector<bool> isprime(N + 1, true);
  vector<int> prime;
  for (int i = 2; i * i <= N; ++i) {
    if (isprime[i]) {
      for (int j = 2; i * j <= N; ++j) {
        isprime[i * j] = false;
      }
    }
  }
  rep(i, 2, N + 1) {
    if (isprime[i]) {
      prime.push_back(i);
      vec[i][i]++;
    }
  }

  rep(i, 2, N + 1) {
    rep(j, 0, prime.size()) {
      if (i * prime[j] <= N) {
        vec[i * prime[j]] = vec[i];
        vec[i * prime[j]][prime[j]]++;
      }
    }
  }
  ll ans = 0;
  rep(i, 1, N + 1) {
    ll cnt = 1;
    if (i != 1) {
      for (auto v : vec[i]) {
        cnt *= (v.second + 1);
      }
    }
    ans += i * cnt;
  }
  cout << ans << "\\n";

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

#include <bits/stdc++.h>

#define FLASH                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << '=' << (x) << endl;
#define mxn 300005
using namespace std;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define FLASH                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << '=' << (x) << endl;
#define mxn 300005
using namespace std;

ll n, ans = 0;
ll count(ll k) {
  ll val = 0;
  for (ll i = k; i <= n; i++) {
    ll cnt = 0;
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        cnt++;
        if (j != i / j) {
          cnt++;
        }
      }
    }
    val += i * cnt;
  }
  return val;
}
int main() {
  FLASH
  cin >> n;
  ll dp[11];
  dp[1] = 7235062807366;
  dp[2] = 30326413365285;
  dp[3] = 39732372094995 + dp[2];
  dp[4] = 56791763557524 + dp[3];
  dp[5] = 74141892228888 + dp[4];
  dp[6] = 91718882835249 + dp[5];
  dp[7] = 109477502262108 + dp[6];
  dp[8] = 127392805930085 + dp[7];
  dp[9] = 145439883645536 + dp[8];
  dp[10] = 163605772540435 + dp[9];
  ll val = 1;
  for (ll i = 1; i <= 10; i++) {
    if (i * 1000000 <= n)
      ans = dp[i];
    else {
      ans += count((i - 1) * 1000000 + 1);
      break;
    }
  }
  cout << ans;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000005
#define ll long long int
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int m, sum = 0, k = 0, i, dd = 0, j, sum1 = 0, x, sum2 = 0,
                   sum3 = 0, l, kk, sum4 = 0, sum5 = 0, y, z, sum6 = 0, cc = 0;
  ll n;
  cin >> n;
  ll a[n + 1], b[n + 1] = {0};
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= n; j += i)
      b[j]++;
  }
  for (i = 1; i <= n; i++)
    sum += i * b[i];
  cout << sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000005
#define ll long long int
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int m, sum = 0, k = 0, c, i, d = 0, j, sum1 = 0, x, sum2 = 0,
                   sum3 = 0, l, kk, sum4 = 0, sum5 = 0, y, z, sum6 = 0;
  ll n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    c = 0;
    for (j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (j != i / j)
          c += 2;
        else
          c += 1;
      }
    }
    sum += c * i;
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int n;
  cin >> n;

  vector<int> factors(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      factors[j]++;
  }
  typedef long long ll;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    sum += (i * (ll)factors[i]);
  }

  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int factors(int n) {
  if (n == 1)
    return 1;
  int f = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0 && (n / i != i))
      f += 2;
    else if (n % i == 0 && (n / i == i))
      f++;
  }
  return f;
}

int main() {

  int n;
  cin >> n;

  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum + (i * factors(i));
  }

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

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

// #include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) REP(i, 0, n)

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")

using ll = long long int;

int gcd(int a, int b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll beki(ll a, ll b) {
  ll tmp = 1;
  rep(i, b) tmp *= a;
  return tmp;
}

ll N;

int main() {
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll Y = N / i; // Y項存在する
    // 初項X、階差Yの階差数列
    ans += Y * (i + i * Y) / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

// #include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) REP(i, 0, n)

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")

using ll = long long int;

int gcd(int a, int b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll beki(ll a, ll b) {
  ll tmp = 1;
  rep(i, b) tmp *= a;
  return tmp;
}

ll M;

int main() {
  std::cin >> M;
  vector<ll> res, res2;
  ll ans = 0;
  for (ll N = 1; N <= M; N++) {
    for (ll i = 1; i * i <= N; ++i) {
      if (N % i == 0) {
        res.emplace_back(i);
        ans += N;
        if (i != N / i) {
          res.emplace_back(N / i);
          ans += N;
        }
      }
    }
  }
  cout << ans << endl;
}

/*
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1 1000000000 1000000000 1000000000

5 4 1
1 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
*/
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
// find_by_order(x) -> returns an iterator to the element at a given position
// order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;

const int mod = (int)1e9 + 7;
const int MAXN = 2e5 + 12;
// indexed_set s;

int n;

int main() {

  NoType;

  cin >> n;
  ll m[n + 1] = {0};

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

  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
// find_by_order(x) -> returns an iterator to the element at a given position
// order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;

const int mod = (int)1e9 + 7;
const int MAXN = 2e5 + 12;
// indexed_set s;

int n;

int main() {

  NoType;

  cin >> n;
  int m[n + 1];
  for (int i = 1; i <= 10000000; i++)
    m[i] = 0;

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

  cout << ans;

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

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

const int MOD = 1000000007;
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    ll ni = n / i;
    sum += i * ni * (ni + 1) / 2;
  }

  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

map<ll, int> prime_fact(ll n) {
  map<ll, int> m;
  m[1] = 0; // 1は素数で割れない
  for (ll p = 2; p * p <= n; p++) {
    if (n % p)
      continue; // 素因数でない
    int num = 0;
    while (!(n % p)) { // 素因数で何回割れるかを計算する
      num++;
      n /= p;
    }
    m[p] = num;
  }
  if (n > 1) { // n自身が素数のときは、素因数は自身のみ
    m[n] = 1;
  }

  return m;
}

vector<bool> make_is_prime(ll N) {
  vector<bool> prime(N + 1, true);
  if (N >= 0)
    prime[0] = false;
  if (N >= 1)
    prime[1] = false;
  for (ll i = 2; i * i <= N; i++) {
    if (!prime[i])
      continue;
    for (ll j = i * i; j <= N; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main() {
  ll n;
  cin >> n;
  auto is_prm = make_is_prime(n);

  ll sum = 1;
  for (ll k = 2; k <= n; k++) {
    if (is_prm[k]) {
      sum += k * 2;
    } else {
      auto m = prime_fact(k);
      ll tmp = 1;
      for (auto l : m) {
        tmp *= l.second + 1;
      }
      sum += k * tmp;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

typedef unsigned long long ull;

int main() {
  ull n;
  std::cin >> n;
  ull ans = 0;
  for (ull i = 1; i <= n; i++) {
    ull top = n / i;
    ans += (top * (top + 1)) * i / 2;
  }
  std::cout << ans << '\\n';
  return 0;
}

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


Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

bool check(long long middle, std::vector<long long> &A,
           std::vector<long long> &B, long long k, long long n, long long m) {
  long long time = 4294967295;
  for (long long i = 0; i <= n; i++) {
    if (middle - i <= m)
      time = std::min(time, A[i] + B[middle - i]);
    if (time <= k)
      return true;
  }
  if (time > k)
    return false;
  return true;
}

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;
  std::vector<long long> A(n + 1);
  std::vector<long long> B(m + 1);
  A[0] = 0;
  B[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    long long a;
    std::cin >> a;
    A[i] = a + A[i - 1];
  }
  for (int i = 1; i < m + 1; i++) {
    long long b;
    std::cin >> b;
    B[i] = b + B[i - 1];
  }
  long long ans = 0;
  for (long long book = 1; book <= n + m; book++) {
    if (check(book, A, B, k, n, m))
      ans = std::max(ans, book);
  }
  std::cout << ans << '\\n';
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_one(i, n) for (int i = 1; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep_one(k, n + 1) {
    ll tmp = n / k;
    ans += k * tmp * (1 + tmp) / 2;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_one(i, n) for (int i = 1; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int prime[n + 1];
  rep(i, n + 1) prime[i] = 0;
  for (int i = 2; i * i < n + 1; i++) {
    for (int j = i; j < n + 1; j += i) {
      if (prime[j] == 0)
        prime[j] = j / i;
    }
  }
  map<int, int> div[n + 1];
  for (int i = 2; i < n + 1; i++) {
    if (prime[i] == 0)
      div[i][i] = 1;
    else {
      int tmp = i / prime[i];
      div[i] = div[prime[i]];
      div[i][tmp] += 1;
    }
  }
  ll ans = 1;
  for (int i = 2; i < n + 1; i++) {
    int div_count = 1;
    for (auto itr = div[i].begin(); itr != div[i].end(); itr++) {
      // cout << "key=" << itr->first << " value=" << itr->second << endl;
      div_count *= itr->second + 1;
    }
    ans += i * div_count;
    // cout << "i=" << i << " div_count="<< div_count << endl << endl;
  }
  cout << ans << endl;
}