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

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

int sos(int);

int pri[10000000];

int main() {
  int x;
  while (scanf("%d", &x) != EOF) {
    printf("%d\\n", sos(x));
  }
  return 0;
}

int sos(int a) {
  int i, j, c = 0, b;
  for (j = 2; j <= a; j++) {
    b = 0;
    if (pri[j] == 3)
      continue;
    if (pri[j] == 1) {
      c++;
      continue;
    }
    for (i = 2; i <= sqrt(j); i++) {
      if (j % i == 0) {
        pri[j] = 3;
        b = 1;
        break;
      }
    }
    if (b == 0) {
      pri[j] = 1;
      c++;
    }
  }
  return c;
}

Error: TLE

Fixed submission:

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

int sos(int);

int pri[10000000];

int main() {
  int x;
  while (scanf("%d", &x) != EOF) {
    printf("%d\\n", sos(x));
  }
  return 0;
}

int sos(int a) {
  int i, j, c = 0, b;
  for (j = 2; j <= a; j++) {
    b = 0;
    if (pri[j] == 3)
      continue;
    for (i = 2; i <= sqrt(j); i++) {
      if (j % i == 0) {
        pri[j] = 3;
        b = 1;
        break;
      }
    }
    if (b == 0) {
      pri[j] = 1;
      c++;
    }
  }
  return c;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>

const int N = 1000009;
int dp[N];
int isprime[N];

int main() {
  dp[1] = 0;
  for (int i = 2; i < N; i++) {
    if (!isprime[i])
      for (int j = 2 * i; j < N; j += i)
        isprime[j] = 1;
    dp[i] = dp[i - 1] + ((isprime[i]) ? 0 : 1);
  }

  int y;
  while (~scanf("%d", &y))
    printf("%d\\n", dp[y]);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>

const int N = 19;
int dp[N];
int isprime[N];

int main() {
  dp[1] = 0;
  for (int i = 2; i < N; i++) {
    if (!isprime[i])
      for (int j = 2 * i; j < N; j += i)
        isprime[j] = 1;
    dp[i] = dp[i - 1] + ((isprime[i]) ? 0 : 1);
  }

  int y;
  while (~scanf("%d", &y))
    printf("%d\\n", dp[y]);
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  bool is_prime[1000000];

  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    is_prime[i] = true;
  }

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

  int n_prime[1000000];

  int cnt = 0;
  for (int i = 0; i < 1000000; i++) {
    if (is_prime[i]) {
      cnt++;
    }
    n_prime[i] = cnt;
  }

  while (true) {
    int n;
    cin >> n;
    if (cin.eof())
      break;

    cout << n_prime[n] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool is_prime[100000];

  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000; i++) {
    is_prime[i] = true;
  }

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

  int n_prime[100000];

  int cnt = 0;
  for (int i = 0; i < 100000; i++) {
    if (is_prime[i]) {
      cnt++;
    }
    n_prime[i] = cnt;
  }

  while (true) {
    int n;
    cin >> n;
    if (cin.eof())
      break;

    cout << n_prime[n] << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8

static const double PI = 6 * asin(0.5);
typedef complex<double> P;
typedef long long ll;

int t;

int main() {
  int *prime;
  prime = (int *)malloc(1000010 * sizeof(t));
  if (prime == NULL)
    cout << "no mem\\n";
  rep(i, 1000010) { prime[i] = true; }
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < 1000010; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 1000010; j += i) {
        prime[j] = false;
      }
    }
  }

  int *sum;
  int num = 0;
  sum = (int *)malloc(1000010 * sizeof(t));
  if (sum == NULL)
    cout << "no mem\\n";
  rep(i, 1000010) {
    if (prime[i]) {
      num++;
    }
    sum[i] = num;
  }
  int n;
  while (cin >> n) {
    cout << sum[n] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8

static const double PI = 6 * asin(0.5);
typedef complex<double> P;
typedef long long ll;

int t;

int main() {
  int *prime;
  prime = (int *)malloc(100010 * sizeof(t));
  if (prime == NULL)
    cout << "no mem\\n";
  rep(i, 100010) { prime[i] = true; }
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < 100010; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 100010; j += i) {
        prime[j] = false;
      }
    }
  }

  int *sum;
  int num = 0;
  sum = (int *)malloc(100010 * sizeof(t));
  if (sum == NULL)
    cout << "no mem\\n";
  rep(i, 100010) {
    if (prime[i]) {
      num++;
    }
    sum[i] = num;
  }
  int n;
  while (cin >> n) {
    cout << sum[n] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#define N 1000000

int main() {
  int ipt;
  int root;
  int cnt = 0;
  int A[N];
  for (int i = 1; i <= N; i++) {
    A[i] = i;
  }
  for (int pos = 2; pos * pos <= N; pos++) {
    root = A[pos];
    if (!root)
      continue;
    for (int k = 2; k * root <= N; k++) {
      A[k * root] = 0;
    }
  }

  while (scanf("%d", &ipt) == 1) {
    for (int i = 2; i <= ipt; i++) {
      if (A[i] != 0)
        cnt++;
    }
    printf("%d\\n", cnt);
    cnt = 0;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#define N 1000000

int main() {
  int ipt;
  int root;
  int cnt = 0;
  int A[N];
  for (int i = 1; i <= N; i++) {
    A[i] = i;
  }
  for (int pos = 2; pos * pos <= N; pos++) {
    root = A[pos];
    if (!root)
      continue;
    for (int k = 2; k * root <= N; k++) {
      A[k * root] = 0;
    }
  }

  while (1) {
    scanf("%d", &ipt);
    for (int i = 2; i <= ipt; i++) {
      if (A[i] != 0)
        cnt++;
    }
    printf("%d\\n", cnt);
    cnt = 0;
  }

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

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

int main() {
  int n;

  while (cin >> n) {
    int count = 0;
    bool table[1000001] = {false};
    int upper = sqrt(n);

    table[1] = true;

    for (int i = 1; i <= upper; i++) {
      if (table[i] == false) {
        table[i] = true;
        count++;
        for (int j = i; j <= n; j += i) {
          table[j] = true;
        }
      }
    }

    for (int i = upper; i <= n; i++) {
      if (table[i] == false) {
        count++;
      }
    }

    cout << count << '\\n';
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;

  while (cin >> n) {
    int count = 0;
    bool table[1000001] = {false};
    int upper = sqrt(n);

    table[1] = true;

    for (int i = 1; i <= upper; i++) {
      if (table[i] == false) {
        table[i] = true;
        count++;
        for (int j = i; j <= n; j++) {
          if (j % i == 0) {
            table[j] = true;
          }
        }
      }
    }

    for (int i = 1; i <= n; i++) {
      if (table[i] == false) {
        count++;
      }
    }

    cout << count << '\\n';
  }

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

#include <cstdio>

bool isprime[1000000];

void eratos() {
  for (int i = 0; i < 1000000; i++) {
    isprime[i] = true;
  }
  isprime[0] = isprime[1] = false;
  for (int i = 2; i <= 1000; i++) {
    if (isprime[i] == true) {
      int j = i + i;
      while (j < 1000000) {
        isprime[j] = false;
        j = j + i;
      }
    }
  }
}

int main(void) {
  int n;
  eratos();
  while (scanf("%d", &n) != EOF) {
    int cnt = 0;
    for (int i = 0; i <= n; i++) {
      if (isprime[i] == true) {
        cnt++;
      }
    }
    printf("%d\\n", cnt);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
int solve(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int cnt = 0;
    for (int i = 2; i <= n; i++) {
      cnt += solve(i);
    }
    printf("%d\\n", cnt);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  const int N_MAX = 1000000;
  int i, j, n[32], ni, soi, max;
  int so[N_MAX], count[N_MAX];

  for (i = 0; i < N_MAX; i++)
    so[i] = 1;
  ni = 0;
  max = 0;
  while (cin >> n[ni])
    if (n[ni++] > max)
      max = n[ni - 1];
  int sq_max = (int)sqrt(max);
  so[0] = so[1] = 0;
  for (soi = 0, i = 2; i <= sq_max; i++) {
    if (so[i] == 0)
      continue;
    for (j = i * 2; j <= max; j += i)
      so[j] = 0;
  }
  for (i = 2; i <= max; i++) {
    count[i] = count[i - 1] + so[i];
  }
  for (i = 0; i < ni; i++)
    cout << count[n[i]] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  const int N_MAX = 100;
  int i, j, n[32], ni, soi, max;
  int so[N_MAX], count[N_MAX];

  for (i = 0; i < N_MAX; i++)
    count[i] = so[i] = 0;
  ni = 0;
  max = 0;
  while (cin >> n[ni])
    if (n[ni++] > max)
      max = n[ni - 1];
  int sq_max = (int)sqrt(max);
  so[0] = so[1] = 1;
  for (soi = 0, i = 2; i <= sq_max; i++) {
    if (so[i] > 0)
      continue;
    for (j = i * 2; j <= max; j += i)
      so[j] = 1;
  }
  for (i = 2; i <= max; i++) {
    count[i] = count[i - 1] + 1 - so[i];
  }
  for (i = 0; i < ni; i++)
    cout << count[n[i]] << endl;

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

#include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V + 1];
int sum[MAX_V + 2];
int main() {
  int i, k, n;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  for (i = 0; i < MAX_V + 1; i++) {
    sum[i + 1] += sum[i] + prime[i];
  }
  while (scanf("%d", &n) != EOF) {
    printf("%d\\n", sum[n + 1]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
const int MAX_V = 10000;
int prime[MAX_V + 1];
int main() {
  int i, k, n, p, q, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (v = 2; v <= n - 2; v++) {
      int isprime = prime[v] * prime[v + 2];
      if (isprime)
        p = v, q = v + 2;
    }
    printf("%d %d\\n", p, q);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long n, i, j, k, sum = 0, num, SUM = 0;
  for (i = 0; i < 30; i++) {
    cin >> n;
    for (j = 1; j <= n; j++) {
      for (k = j; k >= 1; k--) {
        num = j / k * k;
        if (num == j)
          sum++;
      }
      if (sum == 2)
        SUM++;
      sum = 0;
    }
    cout << SUM << endl;
    SUM = 0;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  vector<int> prime_num{2, 3};
  int n;

  while (cin >> n) {
    int result;
    if (n <= 1) {
      result = 0;
    } else if (n == 2) {
      result = 1;
    } else if (n < prime_num.back()) {
      result = count_if(prime_num.begin(), prime_num.end(),
                        [n](int a) { return a <= n; });
    } else {
      for (int i = prime_num.back() + 2; i <= n; i += 2) {
        int temp = static_cast<int>(sqrt(i));
        auto it = find_if(prime_num.begin(), prime_num.end(),
                          [temp](int a) { return a > temp; });
        if (all_of(prime_num.begin(), it,
                   [i](int a) { return (i % a) != 0; })) {
          prime_num.push_back(i);
        }
      }
      result = prime_num.size();
    }

    cout << result << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  vector<int> prime_num{2, 3};
  int n;

  while (cin >> n) {
    int result;
    if (n <= 1) {
      result = 0;
    } else if (n == 2) {
      result = 1;
    } else if (n < prime_num.back()) {
      result = count_if(prime_num.begin(), prime_num.end(),
                        [n](int a) { return a <= n; });
    } else {
      for (int i = prime_num.back() + 2; i <= n; i += 2) {
        if (all_of(prime_num.begin(), prime_num.end(),
                   [i](int a) { return (i % a) != 0; })) {
          prime_num.push_back(i);
        }
      }
      result = prime_num.size();
    }

    cout << result << endl;
  }

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

#include <cmath>
#include <iostream>

int table[1000000];

using namespace std;

void init() {
  for (int i = 0; i < 1000000; i++)
    table[i] = 0;
  for (int i = 2; i < 1000000; i++) {
    if (table[i] != -1) {
      table[i] = table[i - 1] + 1;
      for (int j = i + i; j < 1000000; j += i)
        table[j] = -1;
    } else {
      table[i] = table[i - 1];
    }
  }
}

int main(void) {
  int n;
  init();
  while (cin >> n) {
    cout << table[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

bool isprime_ge3(int n) {
  if (!(n & 1))
    return false;
  int lim = (int)sqrt((double)n);
  for (int i = 3; i <= lim; i += 2)
    if (!(n % i))
      return false;
  return true;
}

int main(void) {
  int n;
  while (cin >> n) {
    if (n < 2)
      cout << 0 << endl;
    else if (n == 2)
      cout << 1 << endl;
    else {
      int total = 1;
      for (int i = 3; i <= n; i++) {
        if (isprime_ge3(i))
          total++;
      }
      cout << total << endl;
    }
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>

using namespace std;
typedef long long Int;
#define REP(i, x) for (int i = 0; i < x; ++i)

typedef pair<int, int> P;

bool dp[10000100];

int main() {
  int N;
  while (cin >> N) {
    long ans(0);
    dp[0] = dp[1] = true;
    for (int i = 2; i * i <= N; ++i) {
      if (!dp[i]) {
        for (int j = 2 * i; j <= N; j += i)
          dp[j] = true;
      }
    }
    for (int i = 2; i <= N; ++i) {
      ans += !dp[i];
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>

using namespace std;
typedef long long Int;
#define REP(i, x) for (int i = 0; i < x; ++i)

typedef pair<int, int> P;

bool dp[10000100];

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

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

bool prime[1000000];
int cou[1000000] = {0};

int main() {
  int n;

  rep(i, 1000000) prime[i] = true;
  prime[1] = false;
  for (int i = 1; i * i < 1000000; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 1000000; j += i) {
        prime[j] = false;
      }
    }
  }
  rep(i, 999999) {
    if (prime[i + 1])
      cou[i + 1] = cou[i] + 1;
    else
      cou[i + 1] = cou[i];
  }
  while (cin >> n) {
    cout << cou[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  vector<int> prime;
  int count = 0;
  int tmp[3][100];
  int k = 0, max = 0;
  while (cin >> n) {
    tmp[0][k++] = n;
    if (max < n)
      max = n;
    if (n == 1) {
      tmp[1][k - 1] = 0;
    } else if (n == 2) {
      tmp[1][k - 1] = 1;
    } else if (n == 3) {
      tmp[1][k - 1] = 2;
    }
  }
  // cout<<"hoge\\n";
  prime.push_back(2);
  prime.push_back(3);
  // count[1]=0;
  // count[2]=1;
  // count[3]=2;
  // cout<<"hoge\\n";
  count = 2;
  for (int i = 4; i < max + 1; i++) {
    /*if(i%2==0){
            count[i]=prime.size();
    }
    else if(i%3==0){
            count[i]=prime.size();
    }
    else{
            */
    count++;
    prime.push_back(i);
    for (int j = 0; j < prime.size() - 1; j++) {
      if (i % prime[j] == 0) {
        count--;
        prime.pop_back();
        break;
      }
    }
    for (int j = 0; j < k; j++) {
      if (tmp[0][j] == i) {
        tmp[1][j] = count;
      }
    }
    //}
  }
  // cout<<"hoge";
  /*for(int i=0;i<15;i++){
          cout<< count[i] << endl;
  }*/
  for (int j = 0; j < k; j++) {
    cout << tmp[1][j] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
#define MAX 1000000

int main() {
  bool work[MAX];
  int num;

  // 初期化
  for (int i = 0; i < MAX; i++) {
    if (i < 2) {
      work[i] = false;
    } else {
      work[i] = true;
    }
  }

  // エラトネスのふるい
  for (int i = 2; i < sqrt((double)MAX) + 1; i++) {
    if (work[i] == true) {
      for (int j = i * 2; j < MAX; j += i) {
        work[j] = false;
      }
    }
  }

  // 入力
  while (cin >> num) {
    int ans = 0;

    // 計算
    for (int i = 0; i <= num; i++) {
      if (work[i] == true) {
        ans++;
      }
    }
    // 出力
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 1000000

int main() {
  bool work[MAX + 1];
  int num, ans = 0;

  // 初期化
  for (int i = 6; i <= MAX; i++) {
    for (int j = 2; j < (i / 2); j++) {
      if (i % j == 0) {
        work[i] = false;
        break;
      } else {
        work[i] = true;
      }
    }
  }
  work[0] = false;
  work[1] = false;
  work[2] = true;
  work[3] = true;
  work[4] = false;
  work[5] = true;

  // 出力
  while (cin >> num) {
    for (int i = 0; i <= num; i++) {
      if (work[i] == true) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MAX_VALUE = 1000000;

class PrimeNumbers {
public:
  vector<bool> primeNumbers;

  PrimeNumbers() { this->createPrimeNumbers(); }

  int answer(int N) {
    int result = 0;
    for (int i = 0; i <= N; i++) {
      if (this->primeNumbers[i]) {
        result++;
      }
    }
    return result;
  }

  void createPrimeNumbers() {

    this->primeNumbers = vector<bool>(MAX_VALUE, true);
    this->primeNumbers[0] = false;
    this->primeNumbers[1] = false;
    for (long long i = 2; i < MAX_VALUE; i++) {
      for (long long j = i * i; j < MAX_VALUE; j += i) {
        this->primeNumbers[j] = false;
      }
    }
  }
};

int main() {
  int N;
  PrimeNumbers pn = PrimeNumbers();

  while (cin >> N) {
    cout << pn.answer(N) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

class PrimeNumbers {
public:
  vector<int> primeNumbers;

  PrimeNumbers() { this->createPrimeNumbers(); }

  int answer(int N) {
    int result = 0;
    for (auto it = this->primeNumbers.begin(); it != this->primeNumbers.end();
         it++) {
      if (*it <= N)
        result++;
      else
        break;
    }
    return result;
  }

  bool checkOf(int n) {
    if (n % 2 == 0)
      return false;

    bool prime = false;
    for (auto it = this->primeNumbers.begin(); it != this->primeNumbers.end();
         it++) {
      if (n == *it) {
        prime = true;
        break;
      }
    }
    return prime;
  }

  void createPrimeNumbers() {
    int max_number = 999999 + 1;
    this->primeNumbers = vector<int>();
    this->primeNumbers.push_back(2);
    for (int i = 3; i < max_number; i += 2) {
      bool prime = true;
      for (auto it = this->primeNumbers.begin(); it != this->primeNumbers.end();
           it++) {
        if (i % *it == 0) {
          prime = false;
          break;
        }
      }
      if (prime) {
        this->primeNumbers.push_back(i);
      }
    }
  }
};

int main() {
  int N;
  PrimeNumbers pn = PrimeNumbers();
  while (cin >> N) {
    cout << pn.answer(N) << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, MAX_N = int(1e6);

int main() {

  int n, i, j, maxin = 2;
  bool jud;
  vector<int> vec;
  for (i = 2; i <= MAX_N; i++) {
    jud = 0;
    for (j = 0; j < vec.size(); j++) {
      if (vec[j] * vec[j] > i)
        break;
      if (!(i % vec[j])) {
        jud = 1;
        break;
      }
    }
    if (!jud)
      vec.push_back(i);
  }
  while (cin >> n) {
    cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin() << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, Array = int(1e6);

int main() {

  int n, i, j, maxin = 0;
  bool jud;
  vector<int> vec;

  while (cin >> n) {
    if (maxin < n) {
      maxin = n;
      for (i = 2; i <= n; i++) {
        jud = 0;
        for (j = 0; j < vec.size(); j++) {
          if (!(i % vec[j])) {
            jud = 1;
            break;
          }
        }
        if (!jud)
          vec.push_back(i);
      }
    }
    cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin() << endl;
  }
}