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

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

#define MAX 1000000

int main(void) {

  bool p[MAX + 1];
  int n, ans;

  for (int i = 0; i <= MAX; i++) {
    p[i] = (i <= 1) ? false : true;
  }

  for (int i = 2; i <= (sqrt((double)MAX)) + 1; i++) {
    if (p[i]) {
      for (int j = i * 2; j <= MAX; j = j + i) {
        p[j] = false;
      }
    }
  }

  while (cin >> n) {
    ans = 0;
    for (int i = 0; i <= n; i++) {
      if (p[i]) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {

  long int n, f, k, i;
  int count;
  bool chk;
  while (scanf("%d", &n) != EOF) {
    count = 0;
    for (i = 2; i <= n; i++) {

      chk = 0;
      f = i / 2;
      k = 2;

      while (f >= k) {
        if ((i % k) == 0) {
          chk = true;
          break;
        }
        k++;
      }

      if (chk == false) {
        count++;
      }
    }
    cout << count << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

static const int MAX = 1000000;

int main() {
  static bool is_prime[MAX] = {false};
  static int npr[MAX];
  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) {
      for (int j = 2; j * i < MAX; j++) {
        is_prime[i * j] = true;
      }
    }
    npr[i] = npr[i - 1] + !is_prime[i];
  }
  int n;
  while (cin >> n) {
    cout << npr[n] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

static const int MAX = 10;

int main() {
  static bool is_prime[MAX] = {false};
  static int npr[MAX];
  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) {
      for (int j = 2; j * i < MAX; j++) {
        is_prime[i * j] = true;
      }
    }
    npr[i] = npr[i - 1] + !is_prime[i];
  }
  int n;
  while (cin >> n) {
    cout << npr[n] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#define M 1000000

using namespace std;

int main() {

  int c, n;
  bool x[M];

  for (int i = 2; i <= M; i++) {
    x[i] = false;
  }
  for (int i = 2; i < 1000; i++) {
    if (x[i])
      continue;
    for (int j = i * 2; j < M; j += i) {
      if (!x[j])
        x[j] = true;
    }
  }

  while (scanf("%d", &n) != EOF) {
    c = 0;
    for (int i = 2; i <= n; i++) {
      if (!x[i])
        c++;
    }
    cout << c << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int prime(int);

int main() {

  int n;

  while (cin >> n) {
    if (n > 999999)
      continue;
    cout << prime(n) << endl;
  }

  return 0;
}

int prime(int n) {

  int i, j, k = 0, count = 0;
  if (n == 0 || n == 1)
    return 0;

  for (i = 2; i <= n; i++) {
    for (j = 2; j < i; j++) {
      if (i % j == 0)
        k = 1;
    }
    if (k == 0)
      count++;
    k = 0;
  }

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

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main() {
  vector<int> prime;
  prime.push_back(2);
  for (long long int i = 3; i < 999999; i++) {
    double temp = sqrt(i);
    for (int j = 0;; j++) {
      if (temp < prime[j]) {
        prime.push_back(i);
        break;
      }
      if (i % prime[j] == 0) {
        break; // this is not prime
      }
    }
  }
  int n;
  int i;
  while (cin >> n) {
    for (i = 0; i < prime.size() && prime[i] <= n; i++)
      ;
    cout << i << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main() {
  vector<int> prime;
  prime.push_back(2);
  for (long long int i = 3; i < 999999; i++) {
    double temp = sqrt(i);
    for (int j = 0;; j++) {
      if (temp < prime[j]) {
        prime.push_back(i);
        break;
      }
      if (i % prime[j] == 0) {
        break; // this is not prime
      }
    }
  }
  int n;
  int i;
  while (cin >> n) {
    for (i = 0; prime[i] <= n; i++)
      ;
    cout << i << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

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

int count_prime(unsigned int const &n) {
  if (n <= 0 || 1000000 <= n)
    return -1;
  std::vector<bool> memo_prime(n + 1, true);
  memo_prime.at(0) = memo_prime.at(1) = false;
  for (unsigned int i = 2; i < n; ++i) {
    for (unsigned int j = 2; i * j <= n; ++j) {
      memo_prime.at(i * j) = false;
    }
  }
  return std::count(memo_prime.begin(), memo_prime.end(), true);
}

int main() {
  int n;
  while (std::cin >> n) {
    std::cout << count_prime(n) << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int count_prime(unsigned int const &n) {
  if (n <= 0 || 1000000 <= n)
    return -1;
  std::vector<bool> memo_prime(n + 1, true);
  for (unsigned int i = 2; i < n; ++i) {
    for (unsigned int j = 2; i * j <= n; ++j) {
      memo_prime.at(i * j) = false;
    }
  }
  memo_prime.at(0) = memo_prime.at(1) = false;
  memo_prime.at(2) = true;
  return std::count(memo_prime.begin(), memo_prime.end(), true);
}

int main() {
  int n;
  while (std::cin >> n) {
    std::cout << count_prime(n) << std::endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#define MAX_N 1000000

int main() {
  bool p[MAX_N + 1]; // p[NUM] : NUM is Prime?
  int n;

  for (int i = 0; i <= MAX_N; i++)
    p[i] = true;

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

  // for(int i = 0; i <= MAX_N; i++) if(p[i]) printf("%d\\n",i);

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

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#define MAX_N 1000000

int main() {
  bool p[MAX_N + 1]; // p[NUM] : NUM is Prime?
  int n;

  for (int i = 0; i <= MAX_N; i++)
    p[i] = true;

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

  // for(int i = 0; i <= MAX_N; i++) if(p[i]) printf("%d\\n",i);

  while (scanf("%d", &n)) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
      if (p[i])
        count++;
    }
    printf("%d\\n", count);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int Count(bool[], int, int);

int main() {
  const int N = 1000000;
  bool num[N];
  for (int i = 0; i < N; i++)
    num[i] = true;

  const int N_MAX = 999999;
  const double MAX = sqrt(N_MAX);
  for (int i = 2; i <= MAX; i++) {
    if (num[i]) {
      for (int j = i; i * j <= N_MAX; j++) {
        num[i * j] = false;
      }
    }
  }

  int data;
  while (cin >> data) {
    cout << Count(num, 2, data) << endl;
  }
}

int Count(bool data[], int begin, int end) {
  int count = 0;
  for (int i = begin; i <= end; i++)
    if (data[i])
      count++;

  return count;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  const int N_MAX = 999999;
  const double MAX = sqrt(N_MAX);

  vector<int> preprime_list, prime_list;

  for (int i = 2; i <= N_MAX; i++) {
    preprime_list.push_back(i);
  }

  while (preprime_list[0] < MAX) {
    for (int i = 1; i < preprime_list.size(); i++) {
      if (preprime_list[i] % preprime_list[0] == 0)
        preprime_list.erase(preprime_list.begin() + i);
    }
    prime_list.push_back(preprime_list[0]);
    preprime_list.erase(preprime_list.begin() + 0);
  }
  prime_list.insert(prime_list.end(), preprime_list.begin(),
                    preprime_list.end());

  int data, count;
  while (cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] <= data;
         i++, count = i)
      ;
    cout << count << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define N 1000000
int p[N];
int main() {
  int i, j, n, cnt;
  for (i = 2; i <= sqrt(N); i++)
    if (!p[i])
      for (j = i * i; j < N; j += i)
        p[j] = 1;
  while (cin >> n) {
    cnt = 0;
    for (i = 2; i <= n; i++)
      if (!p[i])
        cnt++;
    cout << cnt << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define N 100000

int main() {
  int p[N] = {}, i, j, n, cnt;
  for (i = 2; i <= sqrt(N); i++)
    if (!p[i])
      for (j = i * i; j < N; j += i)
        p[j] = 1;
  while (cin >> n) {
    cnt = 0;
    for (i = 2; i <= n; i++)
      if (!p[i])
        cnt++;
    cout << cnt << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
#define MAX_N 1000001

int main() {
  int *count;
  count = (int *)malloc(sizeof(int) * MAX_N);
  int cnt = 0;
  bool *a;
  a = (bool *)malloc(sizeof(bool) * MAX_N);
  a[1] = true;

  for (int i = 2; i < MAX_N; i++) {
    count[i] = cnt;
    if (a[i])
      continue;
    cnt++;
    count[i]++;
    // int k=1;
    long int k = i; // i??\\???????????????????????????
    while (i * k < MAX_N) {
      a[i * k] = true;
      k++;
    }
  }

  int n;
  while (cin >> n) {
    cout << count[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 100001
int main() {
  int n;
  while (cin >> n) {
    vector<int> vec;
    vector<int>::iterator it = vec.begin();
    for (int i = 2; i <= n; i++) {
      int flag = 0;
      it = vec.begin();
      while (it != vec.end()) {
        if (i % *it == 0) {
          flag = 1;
          break;
        }
        it++;
      }
      if (!flag)
        vec.push_back(i);
    }
    it = vec.begin();
    // while(it!= vec.end()){
    //	cout<<*it<<endl;
    //	it++;
    // }
    cout << vec.size() << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX 1000000
/// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=666933#1
int main() {
  bool num[MAX];
  for (int i = 2; i < MAX; i++)
    num[i] = true;

  for (int i = 2; i * i < MAX; i++) {
    for (int j = i; i * j < MAX; j++) {
      num[i * j] = false;
    }
  }
  for (int n, count = 0; cin >> n; cout << count << endl, count = 0) {
    for (int i = 2; i <= n; i++) {
      if (num[i])
        count++;
    }
  }
}


Error: TLE

Fixed submission:

/// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int n;
  while (~scanf("%d", &n)) {
    int cnt = 0;
    for (int i = 3; i <= n; i += 2) {
      int k = 0;
      for (int j = 3; j < sqrt(i); j += 2) {
        if (i % j == 0) {
          k = 1;
          break;
        }
      }
      if (k == 0)
        cnt++;
    }
    printf("%d\\n", cnt);
  }

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

#include <math.h>
#include <stdio.h>

int main() {
  int n[1000000] = {0};
  int i, j;

  for (i = 2; i <= 999999; i++) {
    for (j = 2; j <= (int)sqrt((double)i); j++) {
      if (i % j == 0)
        break;
      if (j == (int)sqrt((double)i) && i % j != 0)
        n[i] = 1;
    }
  }

  n[2] = 1;
  n[3] = 1;

  int k, l;
  while (scanf("%d", &k) != EOF) {
    int m = 0;
    for (l = 2; l <= k; l++) {
      if (n[l] == 1)
        m++;
    }
    printf("%d\\n", m);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int main() {
  int n;
  int i, j;
  while (scanf("%d", &n) != EOF) {
    int m = 2;
    for (i = 2; i <= n; i++) {
      for (j = 2; j <= (int)sqrt((double)i); j++) {
        if (i % j == 0)
          break;
        if (j == (int)sqrt((double)i) && i % j != 0)
          m++;
      }
    }
    printf("%d\\n", m);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int isPrime[1000001];
int main() {

  fill(isPrime, isPrime + 1000001, 1);
  isPrime[0] = isPrime[1] = 0;
  for (int i = 2; i * i < 1000001; i++) {
    if (isPrime[i])
      for (int j = i * 2; j < 1000001; j += i)
        isPrime[j] = 0;
  }
  int n;
  while (cin >> n) {
    int cnt = 0;
    for (int i = 2; i <= n; i++) {
      if (isPrime[i])
        cnt++;
    }
    cout << cnt << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int isPrime[1000001];
int main() {

  fill(isPrime, isPrime + 1000001, 1);
  isPrime[0] = isPrime[1] = 0;
  for (int i = 2; i * i < 1000001; i++) {
    if (isPrime[i])
      for (int j = i * 2; j < 1000001; j += i)
        isPrime[j] = 0;
  }
  int n;
  while (cin >> n, n) {
    int cnt = 0;
    for (int i = 2; i <= n; i++) {
      if (isPrime[i])
        cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
const int M = (1e6);
bool p[M];
void isPrime() {
  rep(i, M) p[i] = true;
  p[0] = p[1] = false;
  loop(i, 2, M) {
    if (p[i])
      for (int j = i + i; j < M; j += i)
        p[j] = false;
  }
}
int main(void) {
  isPrime();
  int n;
  while (cin >> n) {
    int res = 0;
    rep(i, n + 1) res += p[i];
    cout << res << endl;
  }
}

Error: MLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, b, a) for (int i = b; i < a; i++)
const int MAX = (1e8);
bool p[MAX];
void isPrime() {
  rep(i, MAX) p[i] = true;
  p[0] = p[1] = false;
  loop(i, 2, MAX) {
    if (p[i]) {
      for (int j = i + i; j < MAX; j += i) {
        p[j] = false;
      }
    }
  }
}

int main(void) {
  isPrime();
  int n;
  while (cin >> n) {
    int i = n - 1;
    while (!p[i--])
      ;
    cout << ++i << ' ';
    i = n + 1;
    while (!p[i++])
      ;
    cout << --i << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define MAX 1000000
int prime[MAX];
bool is_prime[MAX + 1];

int solve(int n) {
  int p = 0;
  // fill(prime,prime+MAX,true);
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = i + i; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }
  return p;
}
int main(void) {

  long long int n;
  while (cin >> n) {
    cout << solve(n) << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define MAX 10000
bool prime[MAX];
int main(void) {

  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;
  for (int i = 2; MAX > i * i; i++) {
    if (prime[i]) {
      for (int j = i + i; MAX > j * j; j += i) {
        prime[j] = false;
      }
    }
  }
  int n;
  while (cin >> n, n) {
    if (n % 2)
      cout << "0" << endl;
    else {
      int cnt = 0, sum = 0;
      for (int i = 0; i <= n / 2; i++) {
        for (int j = i; j < n; j++) {
          if (prime[i] && prime[j]) {
            if (i + j == n)
              cnt++;
          }
        }
      }
      cout << cnt << endl;
    }
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 1 << 30;
const int MAX_PRIME = 1000010;
bool is_prime[MAX_PRIME + 10];
vector<int> primes;

void init_primes() {
  fill(is_prime, is_prime + MAX_PRIME + 10, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 0; i <= MAX_PRIME; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int k = i + i; k <= MAX_PRIME; k += i) {
        is_prime[k] = false;
      }
    }
  }
}

int main() {
  init_primes();
  primes.push_back(INF);

  int N;
  while (scanf("%d", &N) != EOF) {
    printf("%zu\\n",
           upper_bound(primes.begin(), primes.end(), N) - primes.begin());
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
int cnt, n, prime[1000000];
using namespace std;

void count() {
  int tt = 0, flag;
  prime[tt++] = 2;
  for (int i = 3; i <= n; i++) {
    flag = 1;
    for (int j = 0; prime[j] * prime[j] <= i; j++) {
      if (i % prime[j] == 0) {
        flag = 0;
        break;
      }
    }
    if (flag == 1)
      prime[tt++] = i;
  }
  cout << tt << endl;
}

int main() {
  while (true) {
    cin >> n;
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    count();
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

// Author- Simanta Deb Turja
// Team- AUST_HoyeJabe

#include <bits/stdc++.h>
#define pi acos(-1)

typedef unsigned long long ull;
typedef unsigned long ul;
typedef long long ll;
// typedef push_back pb;

using namespace std;

int SieveOfEratosthenes(int n) {

  bool prime[n + 1];
  ull count = 0;
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= n; p++) {

    if (prime[p] == true) {

      for (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (int p = 2; p <= n; p++)
    if (prime[p])
      count++;
  return count;
}

int main() {
  int n;
  while (cin >> n) {
    cout << SieveOfEratosthenes(n) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, f, counter;
  while (cin >> a) {
    counter = 1;
    for (int i = 3; i <= a; i++) {
      f = 0;
      for (int j = 2; j < i; j++) {
        if (i % j == 0) {
          f = 1;
          break;
        }
      }
      if (f == 0)
        counter++;
    }
    cout << counter << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

/*#include<stdio.h>

int checkPrime(int i)
{
     int p;
    for ( p = 2 ; p <= i - 1 ; p++ )
    {
        if ( i%p == 0 )
            return 0;
    }
    if ( p == i )
        return 1;
}
int main()
{
    int n,sum=0,count=0,rem,i;
    while(scanf("%d",&n)!= EOF){
        for(i=2;i<n-1;++i)
        {
           if(checkPrime(i)==1);
              count++;

        }
        printf("%d",count);
    }
    return 0;
}

/*#include<stdio.h>

int main()
{
   int n, i = 3, count, c;

   printf("Enter the number of prime numbers required\\n");
   scanf("%d",&n);

   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\\n",n);
      printf("2\\n");
   }

   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\\n",i);
         count++;
      }
      i++;
   }

   return 0;
}
*/
/*#include<stdio.h>
#include<math.h>
int main(){

    int n;
    while(scanf("%d",&n)!=EOF){
    int num,i,count=0;
    for(num = 2;num<=n;num++){
         int flag = 1;
         int len = (int) (sqrt(num));
         //printf("%d\\n",len);
         for(i=2;i<=len;i++){
             if(num%i==0){
                flag = 0;
                 break;
             }
        }
        if(flag==1)
            count++;
    }
    printf("%d\\n",count);
    }

   return 0;
}

*/
#include <stdio.h>
#include <string.h>

bool mark[1000000];
void sieve() {
  int N = 1000000;
  memset(mark, true, N + 2);

  mark[0] = mark[1] = false;

  for (int i = 4; i < N + 2; i += 2)
    mark[i] = false;

  for (int i = 3; i * i <= N + 2; i += 2) {
    if (mark[i] == true) {
      for (int j = i * i; j < N + 2; j += 2 * i)
        mark[j] = false;
    }
  }
}
int main() {
  int n;
  sieve();
  while (scanf("%d", &n) != EOF) {
    int count = 0, i;
    for (i = 2; i <= n; ++i) {
      if (mark[i] == true)
        count++;
    }
    printf("%d\\n", count);
  }
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int is_prime(int N) {
  if (N < 2)
    return 0;

  int limit = (int)sqrt(N);
  for (int i = 2; i <= limit; ++i) {
    if (N % i == 0)
      return 0;
  }

  return 1;
}

int main() {
  int num, primes, t = 0;

  while ((scanf("%d", &num) != EOF) && (t <= 30)) {
    ++t;
    primes = 0;

    for (int i = 1; i <= num; ++i) {
      if (is_prime(i))
        ++primes;
    }

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

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mem(name, value) memset(name, value, sizeof(name))
#define loop(i, from, to) for (int i = from; i < to; i++)
#define loopr(i, from, to) for (int i = from; i >= to; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;

const int maxn = 1000000 + 5;
int pr[maxn];
bool is_pr[maxn];

int sieve(int n) {
  int p = 0;
  loop(i, 0, n + 1) is_pr[i] = true;
  is_pr[0] = is_pr[1] = false;
  loop(i, 2, n + 1) {
    if (is_pr[i]) {
      pr[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_pr[j] = false;
    }
  }
  return p;
}

int main() {
  int n;
  while (cin >> n)
    cout << sieve(n) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, j, k, l, n, counter;
bool ara3[200000];
void seive() {
  for (i = 2; i <= 100001; i++) {
    ara3[i] = true;
  }
  ara3[1] = false;
  for (i = 2; i <= 100001; i++) {
    for (j = 2; i * j <= 100001; j++) {
      if (ara3[i] == true) {
        ara3[i * j] = false;
      }
    }
  }
}
int main(void) {
  seive();
  while (cin >> n) {
    counter = 0;
    for (i = 1; i <= n; i++) {
      if (ara3[i] == true) {
        counter++;
      }
    }
    cout << counter << endl;
  }
  return 0;
}