alexjercan/bugnet huggingface dataset:
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a[1000001] = {0};
  for (int i = 0; i < 1000001; i++) {
    a[i] = 1;
  }
  a[0] = 0;
  a[1] = 0;
  for (int i = 0; i < 1000; i++) {
    if (a[i]) {
      for (int j = i * 2; j < 1000001; j += i) {
        a[j] = 0;
      }
    }
  }

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[100001] = {0};
  for (int i = 0; i < 100001; i++) {
    a[i] = 1;
  }
  a[0] = 0;
  a[1] = 0;
  for (int i = 0; i < 100; i++) {
    if (a[i]) {
      for (int j = i * 2; j < 100001; j += i) {
        a[j] = 0;
      }
    }
  }

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

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

#include <iostream>

using namespace std;

bool sosu(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main(void) {
  int n;
  bool flag[1000000];
  for (int i = 1; i <= 999999; i++) {
    flag[i] = sosu(i);
  }
  while (cin >> n) {
    int ans = 0;
    for (int i = 2; i <= n; i++) {
      if (flag[i])
        ans++;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

bool sosu(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main(void) {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 2; i <= n; i++) {
      if (sosu(i))
        ans++;
    }
    cout << ans << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, i, j;
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    int k = 0, a[n];
    a[0] = 2;

    for (i = 3; i <= n; i = i + 2) {
      for (j = 0; j <= k; j++) {
        if (i % a[j] == 0)
          break;
        if (i <= a[j] * a[j]) {
          k++;
          a[k] = i;
          break;
        }
      }
      if (j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    cout << k + 1 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i, j;
  while (cin >> n) {

    int k = 0, a[n];
    a[0] = 2;

    for (i = 3; i <= n; i++) {
      for (j = 0; j <= k; j++) {
        if (i % a[j] == 0)
          break;
        if (i > a[j] / 2) {
          k++;
          a[k] = i;
          break;
        }
      }
      if (j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    for (i = 0; i <= k; i++) {
      cout << a[i] << endl;
    }
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX 1000000

int prime[MAX] = {};

void eratos(void) {
  int i, j;
  prime[0] = 1;
  prime[1] = 1;
  for (i = 2; i < MAX / 2; i++) {
    for (j = 2; i * j <= MAX; j++) {
      prime[i * j] = 1;
    }
  }
}

int main(void) {
  long i, j;
  long n;
  int cnt;
  int prime_cnt;

  eratos();
  while (scanf("%ld", &n) != EOF) {
    prime_cnt = 0;
    for (i = 0; i <= n; i++) {
      if (prime[i] == 0)
        prime_cnt++;
    }
    /*prime_cnt = 0;
    for(i = 0;i < n+1;i++){
            cnt = 0;
            if(i < 2) continue;
            if(i == 2){
                    prime_cnt++;
                    continue;
            }
            for(j = 2;j <= i/2;j++){
                    if(i % j == 0){
                            cnt++;
                            break;
                    }
            }
            if(cnt == 0) prime_cnt++;
    }
    printf("%d\\n",prime_cnt);*/
    printf("%d\\n", prime_cnt);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  long i, j;
  long n;
  int cnt;
  int prime_cnt;

  while (scanf("%ld", &n) != EOF) {
    prime_cnt = 0;
    for (i = 0; i < n + 1; i++) {
      cnt = 0;
      if (i < 2)
        continue;
      if (i == 2) {
        prime_cnt++;
        continue;
      }
      for (j = 2; j <= i / 2; j++) {
        if (i % j == 0) {
          cnt++;
          break;
        }
      }
      if (cnt == 0)
        prime_cnt++;
    }
    printf("%d\\n", prime_cnt);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

const int N = 1000000;
bool flags[N];
int counts[N];

void make_flags_and_counts();

void make_flags_and_counts() {
  fill(flags, flags + N, true);
  flags[0] = false;
  flags[1] = false;

  fill(counts, counts + N, 0);
  for (int i = 2; i < N; ++i) {
    if (flags[i]) {
      for (int j = 2; i * j < N; ++j) {
        flags[i * j] = false;
      }
    }
    counts[i] = flags[i] ? counts[i - 1] + 1 : counts[i - 1];
  }
}

int main() {
  make_flags_and_counts();

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

Error: TLE

Fixed submission:

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

map<int, bool> memo_of_prime;

bool check_prime_number(int n) {
  if (n <= 1)
    return false;
  if (memo_of_prime.find(n) != memo_of_prime.end()) {
    return memo_of_prime[n];
  }

  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0)
      return memo_of_prime[n] = false;
  }

  return memo_of_prime[n] = true;
}

int count_prime_number(int n) {

  int count = 0;
  if (n == 1)
    return 0;
  for (int i = 2; i <= n; ++i) {
    if (check_prime_number(i)) {
      count++;
    }
  }

  return count;
}

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

#include <stdio.h>
int prime[1000000];
int main() {
  prime[0] = -1;
  prime[1] = -1;
  for (int i = 2; i < 1000000; i++) {
    if (prime[i] == 0) {
      prime[i] = 1;
      for (int j = i * 2; j < 1000000; j += i)
        prime[j] = -1;
    }
  }
  int now;
  while (~scanf("%d", &now)) {
    int ans = 0;
    for (int i = 1; i < now + 1; i++)
      if (prime[i] == 1)
        ans++;
    printf("%d\\n", ans);
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, yakusuu, sosuu;
  for (int x = 0; x < 30; x++) {
    cin >> n;
    sosuu = 0;
    for (int i = 1; i <= n; i++) {
      yakusuu = 0;
      for (int j = 1; j <= i; j++) {
        if (i % j == 0)
          yakusuu++;
      }
      if (yakusuu == 2)
        sosuu++;
    }
    cout << sosuu << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int prime(int n) {
  int i, j, r;
  n++;
  vector<int> primes(n);

  for (i = 2; i < n; ++i)
    primes[i] = i;
  for (i = 2; i * i < n; ++i) {
    if (primes[i])
      for (j = i * i; j < n; j += i)
        primes[j] = 0;
  }
  for (i = r = 0; i < n; i++)
    if (primes[i])
      r++;
  return r;
}

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int prime(int n) {
  int i, j, r;
  n++;
  vector<int> primes(n);

  for (i = 2; i < n; ++i)
    primes[i] = i;
  for (i = 2; i * i < n; ++i) {
    if (primes[i])
      for (j = i * i; j < n; j += i)
        primes[j] = 0;
  }
  for (i = r = 0; i < n; i++)
    if (primes[i])
      r++;

  for (i = r; i < n; i++)
    cout << primes[i] << " ";
  cout << endl;
  return r;
}

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>

#define MAX 999999

using namespace std;

int main() {
  int n = 0;
  int count;
  bool flag = false;
  vector<int> sosu;
  sosu.push_back(0);
  sosu.push_back(0);
  sosu.push_back(1);

  count = 1;
  for (int i = 3; i <= MAX; i += 2) {
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        flag = true;
        break;
      }
    }
    if (flag != true) {
      count++;
    } else {
      flag = false;
    }
    sosu.push_back(count);
    sosu.push_back(count);
  }

  while (cin >> n) {
    cout << sosu[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>

using namespace std;

int main() {
  int n = 0;
  int count;
  bool flag = false;

  while (cin >> n) {
    count = 1;
    for (int i = 3; i <= n; i += 2) {
      for (int j = 3; j * j <= i; j += 2) {
        if (i % j == 0) {
          flag = true;
          break;
        }
      }
      if (flag != true) {
        count++;
      } else {
        flag = false;
      }
    }
    cout << count << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    bool *num = new bool[n + 1];
    num[0] = num[1] = true;
    for (int i = 2; i <= n; i++)
      num[i] = false;
    int ans = 0;
    for (int i = 2; i < n; i++) {
      if (num[i] == false) {
        for (int j = i * 2; j <= n; j += i)
          num[j] = true;
      }
    }
    for (int j = 2; j <= n; j++)
      if (num[j] == false)
        ans++;
    cout << ans << '\\n';
    delete[] num;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
bool num[500000];
int main() {
  int n;
  while (cin >> n) {
    num[0] = num[1] = true;
    for (int i = 2; i <= n; i++)
      num[i] = false;
    int ans = 0;
    for (int i = 2; i < n; i++) {
      if (num[i] == false) {
        for (int j = i * 2; j <= n; j += i)
          num[j] = true;
      }
    }
    for (int j = 2; j <= n; j++)
      if (num[j] == false)
        ans++;
    cout << ans << '\\n';
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
int prime[1000000];

int main() {

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

  for (int i = 2; i < 1000000; i++) {

    if (prime[i] == 0) {

      prime[i] = 1;
      for (int j = i * 2; j < 1000000; j += i)
        prime[j] = -1;
    }
  }
  int a;
  while (cin >> a) {

    int count = 0;

    for (int i = 1; i < a + 1; i++)
      if (prime[i] == 1)
        count++;

    cout << count << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

bool isprime(int x);

int main() {
  int prime;

  while (cin >> prime) {

    int count = 0;

    for (int i = 1; i <= prime; i++)
      count += isprime(i);

    cout << count << "\\n";
  }
  return 0;
}

bool isprime(int x) {

  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

  int i = 3;

  while (i <= sqrt(x)) {

    if (x % i == 0)
      return false;
    i += 2;
  }
  return true;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    int num = 0;
    for (int i = 1; i <= n; i++) {
      if (i <= 3) {
        if (i == 2 || i == 3)
          num++;
        continue;
      } else {
        if (i % 2 == 0 || i % 3 == 0)
          continue;
        if (i % 6 != 1 && i % 6 != 5)
          continue;
        bool check = true;
        for (int j = 5; j * j <= i; j += 6) {
          if (i % j == 0)
            check = false;
          if (i % (j + 2) == 0)
            check = false;
          if (check == false)
            break;
        }
        if (check == true)
          num++;
      }
    }
    cout << num << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    int num = 0;
    for (int i = 1; i <= n; i++) {
      if (i <= 3) {
        if (i == 2 || i == 3)
          num++;
        continue;
      } else {
        if (i % 2 == 0 || i % 3 == 0)
          continue;
        if (i % 6 != 1 && i % 6 != 5)
          continue;
        bool check = true;
        for (int j = 5; j < i; j += 2) {
          if (i % j == 0) {
            check = false;
            break;
          }
        }
        if (check == true)
          num++;
      }
    }
    cout << num << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

const int iMAX = 1000000;
const int iMAX_half = 500000;
int isPrime[iMAX];

int main() {
  int n, cnt, sqSize;
  bool prime[iMAX_half];

  cnt = 1;
  sqSize = 1000;
  prime[0] = prime[1] = 0;
  prime[2] = 1;
  for (int i = 3; i < iMAX; i += 2)
    prime[(i - 1) >> 1] = 1;
  for (int i = 3; i < sqSize; i += 2) {
    if (prime[(i - 1) >> 1]) {
      for (int j = i + i + i; j < iMAX; j += (i * 2))
        if (j & 1)
          prime[(j - 1) >> 1] = 0;
    }
  }
  isPrime[0] = isPrime[1] = 0;
  isPrime[2] = 1;
  for (int i = 3; i < iMAX; i += 2) {
    if (prime[(i - 1) >> 1])
      cnt++;
    isPrime[(i - 1) >> 1] = cnt;
  }
  while (cin >> n) {
    if (n == 2)
      cout << 1 << endl;
    else
      cout << isPrime[(n - 1) >> 1] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

bool isPrime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n, cnt;

  while (cin >> n) {
    cnt = 0;
    for (int i = 2; i <= n; i++) {
      if (isPrime(i))
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
#define MAX 1000000
using namespace std;
int main() {
  vector<int> v(MAX);
  for (int i = 0; i < MAX; i++)
    v[i] = true;

  v[0] = v[1] = false;
  for (int i = 2; i < MAX; i++) {
    if (v[i]) {
      for (long long int j = (long long int)i * (long long int)i; j < MAX;
           j += i) {
        v[j] = false;
      }
    }
  }
  for (int i = 2; i < MAX; i++)
    v[i] += v[i - 1];
  while (true) {
    int a;
    cin >> a;
    if (cin.eof())
      break;
    ;
    cout << v[a] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define MAX 1000000
using namespace std;
int main() {
  vector<int> v(MAX);
  for (int i = 0; i < MAX; i++)
    v[i] = true;

  v[0] = v[1] = false;
  for (int i = 2; i < MAX; i++) {
    if (v[i]) {
      for (long long int j = (long long int)i * (long long int)i; j < MAX;
           j += i) {
        cout << i << " " << j << endl;
        v[j] = false;
      }
    }
  }
  for (int i = 2; i < MAX; i++)
    v[i] += v[i - 1];
  while (true) {
    int a;
    cin >> a;
    if (cin.eof())
      break;
    ;
    cout << v[a] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

#define MAX_VALUE 1000000

int get_numprime(int num);

int main(void) {
  int num;

  while (1) {
    cin >> num;
    if (cin.eof())
      break;
    int result = get_numprime(num);
    cout << result << endl;
  }

  return 0;
}

int get_numprime(int num) {
  int numprime = 1; // 2はカウント済み

  bool erat[MAX_VALUE] = {0};

  for (int i = 0; i < num + 1; i++) {
    erat[i] = true;
  }
  erat[0] = false;
  erat[1] = false;
  for (int i = 2; i <= num; i++) {
    if (erat[i]) {
      for (int j = i * 2; j <= num; j += i) {
        erat[j] = false;
      }
    }
  }
  for (int i = 3; i <= num; i += 2) {
    if (erat[i])
      numprime++;
  }

  if (num == 1)
    numprime = 0;

  return numprime;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int get_numprime(int num);

int main(void) {
  int num;

  while (1) {
    cin >> num;
    if (cin.eof())
      break;
    cout << get_numprime(num) << endl;
  }

  return 0;
}

int get_numprime(int num) {
  int numprime = 1; // 2はすでにカウント

  for (int i = 3; i <= num; i += 2) {
    int flag = 1;
    for (int j = 3; j <= sqrt((double)i); j += 2) {
      if (i % j == 0) {
        flag = 0;
        break;
      }
    }
    if (flag == 1)
      numprime++;
  }

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

#include <stdio.h>

int main() {
  int i, k, v, scan, an;
  int MAX_V = 999999;
  int count[MAX_V + 1];
  int prime[MAX_V + 1];
  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;
      }
    }
  }
  count[2] = 0;
  for (i = 2; i <= MAX_V; i++) {
    count[i + 1] = count[i] + prime[i];
  }
  while (scanf("%d", &scan) != EOF) {
    printf("%d\\n", count[scan + 1]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int i, k, v, an1, an2, suu;
  int MAX_V = 10000;
  int prime[MAX_V + 1];
  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", &suu);
    if (suu != 0) {
      for (k = 2; k <= suu; k++) {
        if (prime[k - 2] == 1 && prime[k] == 1) {
          an1 = k - 2;
          an2 = k;
        }
      }
      printf("%d %d\\n", an1, an2);
    } else {
      break;
    }
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int i, k, v, scan, an;
  int MAX_V = 999999;
  int count[MAX_V + 1];
  int prime[MAX_V + 1];
  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;
      }
    }
  }
  count[2] = 0;
  for (i = 2; i <= MAX_V; i++) {
    count[i + 1] = count[i] + prime[i];
  }
  while (scanf("%d", &scan) != EOF) {
    printf("%d\\n", count[scan + 1]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int i, k, v, scan, an;
  int MAX_V = 1000000;
  int count[MAX_V];
  int sum[MAX_V];
  int prime[MAX_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;
      }
    }
  }
  count[0] = 0;
  for (i = 1; i <= MAX_V; i++) {
    count[i] = count[i - 1] + prime[i];
  }
  while (scanf("%d", &scan) != EOF) {
    an = count[scan] - count[0];
    printf("%d\\n", an);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>

const int size = 1000000;
int n[size];

int main() {
  for (int i = 0; i < size; ++i) {
    n[i] = (i < 2) ? false : true;
  }
  for (int i = 0; i < std::sqrt(size); ++i) {
    if (n[i]) {
      for (int j = 2; i * j < size; ++j) {
        n[i * j] = false;
      }
    }
  }

  int m;
  while (~scanf("%d\\n", &m)) {
    int ans = 0;
    for (int i = 0; i <= m; ++i) {
      if (n[i]) {
        ++ans;
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <map>

inline bool fermat_test(int n) {
  if (n < 2) {
    return false;
  } else if (n == 2) {
    return true;
  } else {
    return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
  }
}

inline bool prime_test(int n) {
  if (n < 2) {
    return false;
  } else if (n == 2) {
    return true;
  } else {
    for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
      if ((n %= i) == 0) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  std::map<int, int> m;
  m[3] = 2;
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 5; i <= n; i += 2) {
      if (m.count(i) > 0)
        continue;

      m[i] = m[i - 2] + (fermat_test(i) && prime_test(i));
    }
    printf("%d\\n", m[n % 2 == 0 ? n - 1 : n]);
  }
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  static bool c[1000000] = {true};
  static int t[1000000];
  t[0] = 0;
  for (int i = 2; i < 1000000; i++) {
    if (!c[i]) {
      for (int j = i; i * j < 1000000; j++) {
        c[i * j] = true;
      }
    }
    t[i] = t[i - 1] + !c[i];
  }
  for (int n; cin >> n; n++) {
    cout << t[n] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#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: -11

Fixed submission:

#include <cstdio>

int main() {
  bool cmp[1000000] = {true};
  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; scanf("%d", &n); n++) {
    printf("%d\\n", npr[n]);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    bool array[1000500];
    for (int i = 0; i <= n; i++) {
      array[i] = true;
    }

    int count = 0;
    array[0] = array[1] = false;
    for (int i = 1; i <= n; i++) {
      if (array[i]) {
        count++;
        for (int j = i * 2; j <= n; j += i) {
          array[j] = false;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  bool array[11];
  while (cin >> n) {
    int count = 0;
    array[0] = array[1] = false;
    for (int i = 1; i <= n; i++) {
      if (array[i]) {
        count++;
        for (int j = i * 2; j <= n; j += i) {
          array[j] = false;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  bool unti[1000000];
  fill(unti, unti + 1000000, 0);
  for (int n = 2; n < 1000000; n++) {
    if (unti[n] == 0) {
      for (int a = 2; (a * n) < 1000000; a++) {
        unti[a * n]++;
      }
    }
  }
  int b;
  while (cin >> b) {
    int cnt = (count(unti, unti + b + 1, 0) - 2);
    cout << cnt << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main(void) {
  int unti[1000000];
  for (int n = 2; n < 10000000; n++) {
    if (unti[n] == 0) {
      for (int a = 2; (a * n) < 1000000; a++) {
        if ((a * n) < 1000000)
          unti[a * n]++;
      }
    }
  }
  int b;
  while (cin >> b) {
    int cnt = (count(unti, unti + b + 1, 0) - 2);
    cout << cnt << endl;
  }
  return 0;
}