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

#include <algorithm>
#include <cstdio>

int main() {
  const int N = 104729 + 1;
  bool isPrime[N];
  std::fill(isPrime, isPrime + N, true);
  isPrime[0] = isPrime[1] = false;
  int i, j;
  for (i = 2; i * i <= N; i++) {
    if (isPrime[i])
      for (j = i * 2; j < N; j += i)
        isPrime[j] = false;
  }

  int n;
  int s;
  int count;
  while (scanf("%d", &n), n) {
    i = 3;
    s = 2;
    count = 1;
    while (count != n) {
      if (isPrime[i]) {
        count++;
        s += i;
      }
      i += 2;
    }
    printf("%d\\n", s);
  }
}

Error: TLE

Fixed submission:


#include <iostream>
using namespace std;

int main() {
  long long int i, no, sum = 0, in;
  long long int c;
  while (cin >> in, in != 0) {
    switch (in) {
    case 1:
      sum = 2;
      break;
    case 2:
      sum = 5;
      break;
    default:
      sum = 5;
      c = 2;
      for (no = 5;; no += 2) {
        if (in == c)
          break;
        for (i = 2; i < no; i++) {
          if (no % i == 0)
            break;
        }
        if (no == i) {
          sum += no;
          c++;
        }
      }
      break;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  // prime numbers table
  vector<bool> isPrime(110000, false);
  isPrime[2] = true;
  for (int i = 3; i < 110000; i += 2) {
    isPrime[i] = true;
  }

  for (int i = 3; i < 110000; i += 2) {
    for (int j = i + i; j <= 110000; j += i) {
      isPrime[j] = false;
    }
  }

  int n;
  while (cin >> n && n > 0) {
    int kotae = 0;
    int cnt = 1;
    for (int i = 3; cnt < n; i += 2) {
      if (isPrime[i]) {
        kotae += i;
        cnt++;
      }
    }
    if (n >= 1)
      kotae += 2;

    cout << kotae << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  // prime numbers table
  vector<bool> isPrime(10001, false);
  isPrime[2] = true;
  for (int i = 3; i < 10001; i += 2) {
    isPrime[i] = true;
  }

  for (int i = 3; i < 10001; i += 2) {
    for (int j = i + i; j <= 10001; j += i) {
      isPrime[j] = false;
    }
  }

  int n;
  while (cin >> n && n > 0) {
    int kotae = 0;
    int cnt = 1;
    for (int i = 3; cnt < n; i += 2) {
      if (isPrime[i]) {
        kotae += i;
        cnt++;
      }
    }
    if (n >= 1)
      kotae += 2;

    cout << kotae << endl;
  }

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

#include <iostream>
#include <vector>
using namespace std;
int p[1000000];
int main() {
  int i, j, k = 1;
  vector<int> v(10000);
  v[0] = 2;
  for (i = 3; i < 1000000; i += 2) {
    if (p[i] == 0) {
      v[k] = i + v[k - 1];
      k++;
      if (k >= 10000)
        break;
      for (j = i * 2; j < 1000000; j += i) {
        p[j] = 1;
      }
    }
  }
  while (cin >> i, i) {
    cout << v[i - 1] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int p[10000000];
int main() {
  int i, j, k = 1;
  vector<int> v(10000);
  v[0] = 2;
  for (i = 3; i < 10000000; i += 2) {
    if (p[i] == 0) {
      v[k] = i + v[k - 1];
      k++;
      if (k >= 10000)
        break;
      for (j = i * 2; j < 10000000; j += i) {
        p[j] = 1;
      }
    }
  }
  while (cin >> i, i) {
    cout << v[i - 1] << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>

using namespace std;

int main() {

  int prime[1000000];

  for (int i = 0; i < 1000000; i++)
    prime[i] = 1;

  prime[0] = 0;
  prime[1] = 0;

  for (int i = 2; i < sqrt(1000000); i++) {
    if (prime[i] == 1)
      for (int j = i * 2; j < 1000000; j += i)
        prime[j] = 0;
  }

  while (1) {

    int in;

    cin >> in;
    if (in == 0)
      break;
    int out = 0, sum = 0;
    for (int i = 0; out < in; i++) {
      if (prime[i] == 1) {
        out++;
        sum += i;
      }
    }

    cout << sum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

int main() {

  int prime[100000];

  for (int i = 0; i < 100000; i++)
    prime[i] = 1;

  prime[0] = 0;
  prime[1] = 0;

  for (int i = 2; i < sqrt(100000); i++) {
    if (prime[i] == 1)
      for (int j = i * 2; j < 100000; j += i)
        prime[j] = 0;
  }

  while (1) {

    int in;

    cin >> in;
    if (in == 0)
      break;
    int out = 0, sum = 0;
    for (int i = 0; out < in; i++) {
      if (prime[i] == 1) {
        out++;
        sum += i;
      }
    }

    cout << sum << endl;
  }

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

#include <iostream>
using namespace std;

bool p[1000000];

int main() {

  for (int i = 2; i < 1000000; i++) {
    p[i] = true;
  }

  for (int i = 2; i * i < 1000000; i++) {
    if (p[i]) {
      for (int j = i * 2; j < 1000000; j += i) {
        p[j] = false;
      }
    }
  }

  int n;
  while (cin >> n, n) {
    int c = 0;
    long long sum = 0;

    for (int i = 2; c != n; i++) {
      if (p[i]) {
        sum += i;
        c++;
      }
    }
    cout << sum << endl;
  }
  return (0);
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

bool p[100000000];

int main() {

  for (int i = 0; i < 100000000; i++) {
    p[i] = true;
  }

  for (int i = 2; i * i < 10001; i++) {
    if (p[i]) {
      for (int j = i * i; j < 100000000; j += i) {
        p[j] = false;
      }
    }
  }

  int n;
  while (cin >> n, n) {
    int c = 0;
    long long sum = 0;

    for (int i = 2; c != n; i++) {
      if (p[i]) {
        sum += i;
        c++;
      }
    }

    cout << sum << endl;
  }

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

#include <cmath>
#include <iostream>
using namespace std;
bool prime(int x) {
  for (int i = 2; i <= sqrt((double)x); i++) {
    if (x % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  while (cin >> n, n) {
    int sum = 0;
    for (int i = 2; n >= 1; i++) {
      if (prime(i)) {
        sum += i;
        n--;
      }
    }
    cout << sum << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool prime(int x) {
  for (int i = 2; i < x; i++) {
    if (x % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  while (cin >> n, n) {
    int sum = 0;
    for (int i = 2; n >= 1; i++) {
      if (prime(i)) {
        sum += i;
        n--;
      }
    }
    cout << sum << endl;
  }
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

bool is_prime[300001];

void sieme(int n) {
  int i, j;
  for (i = 0; i <= n; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for (i = 2; i <= n; i++) {
    if (is_prime[i]) {
      for (j = i * 2; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main(void) {
  sieme(300000);
  while (1) {
    long long int ans = 0;
    int n;
    cin >> n;
    if (n == 0)
      break;
    long long int a = 2;
    while (n > 0) {
      if (is_prime[a] == true)
        ans += a, n--;
      a++;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

bool is_prime[100001];

void sieme(int n) {
  int i, j;
  for (i = 0; i <= n; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for (i = 2; i <= n; i++) {
    if (is_prime[i]) {
      for (j = i * 2; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main(void) {
  sieme(100000);
  while (1) {
    long long int ans = 0;
    int n;
    cin >> n;
    if (n == 0)
      break;
    long long int a = 2;
    while (n > 0) {
      if (is_prime[a] == true)
        ans += a, n--;
      a++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>
int isprime(int x) {
  int i;
  if (x == 2) {
    return 1;
  }
  if (x < 2 || x % 2 == 0) {
    return 0;
  }
  i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) {
      return 0;
    }
    i = i + 2;
  }
  return 1;
}
int main() {
  int n, c = 0, l[10001] = {0}, j = 0;
  for (int i = 0; i <= 104730; i++) {
    if (isprime(i)) {
      c += i;
      l[j] = c;
      j++;
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    printf("%d\\n", l[n - 1]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <math.h>
#include <stdio.h>
int isprime(int x) {
  int i;
  if (x == 2) {
    return 1;
  }
  if (x < 2 || x % 2 == 0) {
    return 0;
  }
  i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) {
      return 0;
    }
    i = i + 2;
  }
  return 1;
}
int main() {
  int n, c = 0, l[10001] = {0}, j = 0;
  for (int i = 0; i <= 10000000; i++) {
    if (isprime(i)) {
      c += i;
      l[j] = c;
      j++;
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    printf("%d\\n", l[n - 1]);
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int prime[10001], p = 3, psum[10001], n;
  prime[1] = 2, prime[2] = 3;
  for (int i = 5; p < 10001; i++) {
    int f = 0;
    for (int j = 1; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        f = 1;
        break;
      }
    if (!f)
      prime[p++] = i;
  }
  psum[1] = 2;
  for (int i = 2; i < 10001; i++)
    psum[i] = psum[i - 1] + prime[i];
  while (1) {
    cin >> n;
    if (!n)
      break;
    cout << psum[n] << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int prime[10001], p = 3, psum[10001], n;
  for (int i = 5; i < 10001; i++) {
    int f = 0;
    for (int j = 1; prime[j] * prime[j] <= i; j++) {
      if (i % prime[j] == 0)
        f = 1;
      break;
    }
    if (!f)
      prime[p++] = i;
  }
  psum[1] = 2;
  for (int i = 2; i < 10001; i++) {
    psum[i] = psum[i - 1] + prime[i];
  }
  while (1) {
    cin >> n;
    if (n == 0 || n > 10000)
      break;
    cout << psum[n] << endl;
  }
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
#define m 110000
using namespace std;
int main() {
  int n, cnt;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cnt = 0;
    vector<bool> a(m + 1, true);
    for (int i = 2; i * i <= m; i++)
      if (a[i])
        for (int j = i + i; j <= m; j += i)
          a[j] = false;
    long long sum = 0;
    for (int i = 2; i <= m; i++) {
      if (a[i] != 0 && cnt < n) {
        sum += i;
        cnt++;
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Error: -6
double free or corruption (!prev)


Fixed submission:

#include <iostream>
#include <vector>
#define m 120000
using namespace std;
int main() {
  int n, cnt;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cnt = 0;
    vector<bool> a(m, true);
    for (int i = 2; i * i <= m; i++)
      if (a[i])
        for (int j = i + i; j <= m; j += i)
          a[j] = false;
    int sum = 0;
    for (int i = 2; i <= m; i++) {
      if (a[i] != 0 && cnt < n) {
        sum += i;
        cnt++;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int main() {

  const ll N = 200000;
  bitset<N> sosu;
  int ans[10000];
  int cnt = 0;
  int sum = 0;

  sosu.set();

  for (ll i = 2; i < N; ++i) {
    if (sosu.test(i)) {
      sum += i;
      ans[cnt] = sum;
      ++cnt;
      if (cnt == 10000)
        break;
      for (ll j = i * i; j < N; j += i) {
        sosu.reset(j);
      }
    }
  }

  ll n;
  while (1) {
    cin >> n;
    if (!n)
      break;

    cout << ans[n - 1] << endl;
  }

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  bitset::reset: __position (which is 18446744071562814121) >= _Nb (which is 200000)


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int main() {

  const int N = 200000;
  bitset<N> sosu;
  int ans[10000];
  int cnt = 0;
  int sum = 0;

  sosu.set();

  for (int i = 2; i < N; ++i) {
    if (sosu.test(i)) {
      sum += i;
      ans[cnt] = sum;
      ++cnt;
      if (cnt == 10000)
        break;
      for (ll j = i * i; j < N; j += i) {
        sosu.reset(j);
      }
    }
  }

  ll n;
  while (1) {
    cin >> n;
    if (!n)
      break;

    cout << ans[n - 1] << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;

/*
class ElectronicPetEasy
{
public:
        string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
        {

        }
};
*/

int prime[100000];
bool is_prime[1000000];

void sieve(void) {
  int p = 0;

  REP(1000000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j < 1000000; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  int n, s;

  sieve();

  while (cin >> n, n) {
    s = 0;
    REP(n) { s += prime[i]; }
    cout << s << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;

/*
class ElectronicPetEasy
{
public:
        string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
        {

        }
};
*/

int prime[10000];
bool is_prime[1000000];

void sieve(void) {
  int p = 0;

  REP(1000000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j < 1000000; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  int n, s;

  sieve();

  while (cin >> n, n) {
    s = 0;
    REP(n) s += prime[i];
    cout << s << endl;
  }

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

#include <iostream>

using namespace std;

int main() {
  int prime[10001], p = 3, psum[10001], n;
  prime[1] = 2, prime[2] = 3;
  for (int i = 5; p < 10001; i++) {
    int f = 0;
    for (int j = 1; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        f = 1;
        break;
      }
    if (!f)
      prime[p++] = i;
  }
  psum[1] = 2;
  for (int i = 2; i < 10001; i++)
    psum[i] = psum[i - 1] + prime[i];
  while (1) {
    cin >> n;
    if (!n)
      break;
    cout << psum[n] << endl;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int prime[10001], p = 3, psum[10001], n;
  prime[1] = 2, prime[2] = 3;
  for (int i = 5; p < 10001; i++) {
    int f = 0;
    for (int j = 1; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        f = 1;
        break;
      }
    if (!f)
      prime[p++] = i;
  }
  psum[1] = 2;
  for (int i = 2; i < 100001; i++)
    psum[i] = psum[i - 1] + prime[i];
  while (1) {
    cin >> n;
    if (!n)
      break;
    cout << psum[n] << endl;
  }

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

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
  int N = 200000;
  vi p(N, 1);
  p[0] = p[1] = 0;
  rep(i, N) if (p[i]) for (int j = i + i; j < N; j += i) p[j] = 0;
  vi ps;
  rep(i, N) if (p[i]) ps.pb(i);

  for (int n; cin >> n, n != 0;) {
    int sum = 0;
    rep(i, n) sum += ps[i];
    cout << sum << endl;
  }
  return 0;
}

Error: 0
> ps.size() = 17984


Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
  int N = 200000;
  vi p(N, 1);
  p[0] = p[1] = 0;
  rep(i, N) if (p[i]) for (int j = i + i; j < N; j += i) p[j] = 0;
  vi ps;
  rep(i, N) if (p[i]) ps.pb(i);

  debug(ps.size()) for (int n; cin >> n, n != 0;) {
    int sum = 0;
    rep(i, n) sum += ps[i];
    cout << sum << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int x[1000000], y[100000], n, cnt;
int main() {
  for (int i = 2; i < 200000; i++) {
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        goto E;
      }
    }
    x[i] = 1;
  E:;
  }
  for (int i = 0; i < 200000; i++) {
    if (x[i] == 1) {
      cnt++;
      y[cnt] = y[cnt - 1] + i;
    }
  }
  while (1) {
    cin >> n;
    if (!n) {
      break;
    }
    cout << y[n] << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int x[1000000], y[100000], n, cnt;
int main() {
  for (int i = 2; i < 1000000; i++) {
    for (int j = 2; j <= sqrt(i); j++) {
      if (j % i == 0) {
        goto E;
      }
    }
    x[i] = 0;
  E:;
  }
  for (int i = 0; i < 1000000; i++) {
    if (x[i] == 1) {
      cnt++;
      x[cnt] = x[cnt - 1] + i;
    }
  }
  while (1) {
    cin >> n;
    if (!n) {
      break;
    }
    cout << x[n] << endl;
  }
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <bitset>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

#define MAX 1000000

int main() {
  bitset<MAX + 1> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= MAX; i++) {
    for (int j = i + i; j <= MAX; j += i) {
      is_prime[j] = false;
    }
  }
  vector<int> prime;
  for (int i = 0; i <= MAX; i++) {
    if (is_prime[i]) {
      prime.push_back(i);
    }
  }
  if (prime.size() < 10000) {
    printf("error\\n");
    return 0;
  }

  int N;
  while (scanf("%d ", &N) == 1) {
    if (N == 0) {
      break;
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
      sum += prime[i];
    }
    printf("%d\\n", sum);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bitset>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

#define MAX 1000000

int main() {
  bitset<MAX> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= MAX; i++) {
    for (int j = i + i; j <= MAX; j += i) {
      is_prime[j] = false;
    }
  }
  vector<int> prime;
  for (int i = 0; i < MAX; i++) {
    if (prime[i]) {
      prime.push_back(i);
    }
  }
  if (prime.size() < 10000) {
    printf("error\\n");
    return 0;
  }

  int N;
  while (scanf("%d ", &N) == 1) {
    if (N == 0) {
      break;
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
      sum += prime[i];
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  vector<int> prime;
  int n;

  prime.push_back(2);
  for (int i = 3; prime.size() < 10000; i += 2) {
    for (int j = 0; j < prime.size(); j++) {
      if (i % prime[j] == 0) {
        break;
      }
      if (j == prime.size() - 1) {
        prime.push_back(i);
      }
    }
  }

  while (scanf("%d", &n), n != 0) {

    int total = 0;

    for (int i = 0; i < n; i++) {
      total += prime[i];
    }

    printf("%d\\n", total);
  }

  return (0);
}

Error: MLE

Fixed submission:

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

bool sieve[100000001];

int main() {
  fill(sieve + 2, sieve + 100000001, true);
  vector<int> prime;

  for (int i = 2; i * i <= 100000000; i++) {

    if (sieve[i] == false)
      continue;

    for (int j = i * 2; j <= 100000000; j += i) {
      sieve[j] = false;
    }
    prime.push_back(i);
  }
  int n;
  while (scanf("%d", &n), n != 0) {

    int total = 0;

    for (int i = 0; i < n; i++) {
      total += prime[i];
    }

    printf("%d\\n", total);
  }

  return (0);
}