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

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  bool p[1000000];

  p[0] = 0;
  p[1] = 0;

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

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

  while (cin >> n) {
    int count = 0;
    for (int i = 2; i <= n; i++) {
      if (p[i] == true) {
        count++;
      }
    }

    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    int count = 0;

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

    cout << count << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  bool x[1000000];
  int cou, num;

  while (cin >> num) {
    cou = 0;
    for (int i = 2; i <= num; i++) {
      x[i] = true;
    }
    for (int i = 2; i <= sqrt(num); i++) {
      if (x[i]) {
        for (int j = (i * 2); j <= num; j += i) {
          x[j] = false;
        }
      }
    }

    for (int i = 0; i <= num; i++) {
      if (x[i]) {
        cou++;
      }
    }

    cout << cou << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool x[1000000];

void pri(int num) {
  for (int i = 0; i <= num; i++)
    cout << "x[" << i << "] = " << x[i] << endl;
}

void setbool(int num) {
  x[0] = false;
  x[1] = false;
  for (int i = 2; i <= 1000000; i++)
    x[i] = true;
  for (int i = (num + 1); i <= 1000000; i++)
    x[i] = false;
}

void loop(int num) {
  for (int i = 2; i <= num; i++) {
    if (x[i] == false)
      continue;
    else {
      int j = i;
      while (j < num) {
        j++;
        if (x[j] == true && j % i == 0)
          x[j] = false;
      }
    }
  }
}

int ans() {
  int cou = 0;
  for (int i = 0; i <= 1000000; i++)
    if (x[i] == true)
      cou++;
  return cou;
}

int main() {
  int num, cou = 0, i;

  while (cin >> num) {
    setbool(num);
    loop(num);
    cout << ans() << endl;
  }

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

/* All men have limits. They learn what they are and learn
   not to exceed them, I ignore mine. -Batman           */

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

void wakwaw(int *x) {
  x[1] = 0;
  x[2] = 1;
  for (int i = 3; i <= 1000000; i += 2)
    x[i] = 1;

  for (int i = 3; i <= 1000; i += 2) {
    if (x[i] == 0)
      continue;
    for (int j = 2; i * j <= 1000000; j++)
      x[i * j] = 0;
  }

  for (int i = 3; i <= 1000000; i++)
    x[i] += x[i - 1];
}

int main() {

  int *arr = new int[1000001];
  wakwaw(arr);

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

  return 0;
}

Error: TLE

Fixed submission:

/* All men have limits. They learn what they are and learn
   not to exceed them, I ignore mine. -Batman           */
#include <bits/stdc++.h>
// #include <iostream>
// #include <Windows.h>
using namespace std;
bool prime(int n) {
  if (n == 0 || n == 1)
    return 0;
  else if (n == 2)
    return 1;
  else
    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0)
        return 0;
    }
  return 1;
}

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

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

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

const int MAX = 1000000;
int N;

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

  vector<bool> is_prime(MAX, true);
  vector<int> prime(MAX, 0);
  is_prime[0] = is_prime[1] = false;
  prime[0] = prime[1] = 0;
  int p = 0;
  for (int i = 2; i < MAX; ++i) {
    if (is_prime[i]) {
      for (int j = i * 2; j < MAX; j += i)
        is_prime[j] = false;
    }
  }

  for (int i = 1; i < MAX; ++i) {
    prime[i] = prime[i - 1] + is_prime[i];
  }

  while (cin >> N) {
    cout << prime[N] << '\\n';
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int N;

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

  for (int i = 0; i <= 30; ++i) {
    cin >> N;
    cout << prime[N] << '\\n';
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<int> Prime;
void PrimeCalc() {
  bool IsPrime[1000000];
  for (int i = 0; i < 1000000; i++) {
    IsPrime[i] = true;
  }
  IsPrime[0] = IsPrime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    if (IsPrime[i]) {
      Prime.push_back(i);
      for (int j = 2 * i; j < 1000000; j += i) {
        IsPrime[j] = false;
      }
    }
  }
}

void solve() {
  PrimeCalc();
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i < Prime.size(); i++) {
      if (Prime[i] <= n) {
        ans++;
      } else {
        break;
      }
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool IsPrime(int n) {
  if (n == 2) {
    return true;
  }
  if (n < 2 || n % 2 == 0) {
    return false;
  }
  for (int k = 3; k * k <= n; k += 2) {
    if (n % k == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (IsPrime(i) == true) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PA;
using namespace std;
#define MAX 999999
int main() {

  /*?´???°???????´?????????????*/
  vector<int> Primenumber(MAX + 1, 0);
  /*?´???°???????´???????????????????*/
  int n;
  while (cin >> n) {
    bv check(MAX + 1, true);
    for (int i = 2; i <= n; i++) {
      if (check[i]) {
        /*true?????£?????¨???????????°????????????false??§*/
        for (int j = 2; i * j <= n; j++)
          check[i * j] = false;
      }
    }
    int ans = 0;
    for (int i = 2; i <= n; i++)
      if (check[i])
        ans++;
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PA;
using namespace std;
#define MAX 999999
int main() {

  /*?´???°???????´?????????????*/
  vector<int> Primenumber(MAX + 1, 0);
  /*?´???°???????´???????????????????*/
  int counter = 0;
  int n;
  while (cin >> n) {
    bv check(MAX + 1, true);
    for (int i = 2; i <= n; i++) {
      if (check[i]) {
        /*true?????£?????¨???????????°????????????false??§?????????*/
        for (int j = 2; i * j <= n; j++)
          check[i * j] = false;
        Primenumber[counter] = i;
        counter++;
      }
    }
    int ans = 0;
    for (int i = 2; i <= n; i++)
      if (check[i])
        ans++;
    cout << ans << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LOOP(i, x, n) for (int i = x; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000009;

bool Is_Prime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
vector<int> prime;

signed main() {
  LOOP(i, 1, 1000000) {
    if (Is_Prime(i))
      prime.PB(i);
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    REP(i, prime.size()) {
      if (prime[i] <= n)
        ans++;
      else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000009;

bool Is_Prime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
int p[100100];

signed main() {
  loop(i, 1, 100001) {
    if (Is_Prime(i))
      p[i] = 1;
  }
  rep(i, 10001) p[i + 1] += p[i];
  int m;
  while (cin >> m) {
    cout << p[m] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>

using namespace std;

bool prime(int p) {
  if ((p == 0) || (p == 1)) {
    return false;
  } else if (p == 2) {
    return true;
  } else {
    for (int i = 2; i * i <= p; i++) {
      if (p % i == 0) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int n;
  map<int, bool> p;

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

  while (cin >> n) {
    int count = 0;
    if (n >= 2) {
      count++;
    }
    for (int i = 1; i < n + 1; i = i + 2) {
      if (p[i]) {
        count++;
      }
    }

    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>

using namespace std;

bool prime(int p) {
  if ((p == 0) || (p == 1)) {
    return false;
  } else if (p == 2) {
    return true;
  } else {
    for (int i = 2; i * i <= p; i++) {
      if (p % i == 0) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int n;
  map<int, bool> p;

  while (cin >> n) {
    int count = 0;
    if (n >= 2) {
      count++;
    }
    for (int i = 1; i < n + 1; i = i + 2) {
      if (p[i]) {
        count++;
      } else if (prime(i)) {
        count++;
        p[i] = true;
      }
    }

    cout << count << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;

  bool prim[1000001];
  for (int i = 0; i < 1000001; i++)
    prim[i] = true;
  prim[1] = false;
  for (int i = 3; i < 1000001; i++) {
    if (i % 2 == 0)
      prim[i] = false;
    else if (prim[i]) {
      for (int j = i * 2; j <= 1000001; j += i)
        prim[j] = false;
    }
  }

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

Error: TLE

Fixed submission:

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

int check(int x, int y, int z, int w) {}

int main() {
  int n;
  while (cin >> n) {
    vector<int> prim;
    prim.push_back(2);
    for (int i = 3; i <= n; i++) {
      bool fl = false;
      for (int j = 0; j < prim.size(); j++) {
        if (i % prim[j] == 0) {
          fl = true;
          break;
        }
      }
      if (fl == false)
        prim.push_back(i);
    }
    cout << prim.size() << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, num[999999] = {0}, i, j, ans;

  while (cin >> n) {
    ans = 0;
    for (i = 0; i <= n; i++) {
      num[i] = 1;
    }

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

    for (i = 2; i <= n; i++) {
      if (num[i]) {
        ans++;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int i, j, n, count, prime;

  while (cin >> n) {
    prime = 0;
    for (i = n; i > 1; i--) {
      count = 0;
      for (j = 2; j <= sqrt(i); j++) {
        if (i % j == 0) {
          count++;
        }
      }
      if (count == 0) {
        prime++;
      }
    }
    cout << prime << endl;
  }

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

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

using namespace std;

inline void era(vector<bool> &prime, int num);

using namespace std;

int main(void) {
  int num;

  while (cin >> num) {
    vector<bool> prime((num + 1), true);
    prime[0] = false;
    prime[1] = false;
    era(prime, num);
    cout << count(prime.begin(), prime.end(), true) << endl;
  }
  return 0;
}

void era(vector<bool> &prime, int num) {
  int N = 2;
  while (N <= num) {
    int count = 2;
    while ((count * N) <= num) {
      prime[count * N] = false;
      ++count;
    }
    ++N;
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

void initialize(vector<int> &search_list, int num);

void era(vector<int> &search_list, vector<int> &prime_list, int num);

int main(int argc, char *argv[]) {

  int num;

  while (cin >> num) {
    if (num == 1) {
      cout << 0 << endl;
    } else {
      vector<int> search_list, prime_list;
      initialize(search_list, num);
      era(search_list, prime_list, num);
      cout << prime_list.size() << endl;
    }
  }
  return 0;
}

void initialize(vector<int> &search_list, int num) {
  for (int i = 2; i <= num; ++i) {
    search_list.push_back(i);
  }
  return;
}

void era(vector<int> &search_list, vector<int> &prime_list, int num) {
  do {
    vector<int>::iterator it = search_list.begin();
    int count = 1;
    int N = *it;
    prime_list.push_back(*it);
    while ((N * count) <= num) {
      it = find(search_list.begin(), search_list.end(), (N * count));
      if (it != search_list.end()) {
        it = search_list.erase(it);
      }
      ++count;
    }
  } while (!search_list.empty());
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) {
  prime[length] = p;
  length++;
  return;
}
int main() {
  insert(2);
  for (ll i = 3; i < 1000000; i += 2) {
    for (ll j = 0; j < length; j++)
      if (i % prime[j] == 0)
        goto cont;
      else if (prime[j] > sqrt(i))
        break;
    insert(i);
  cont:;
  }
  ll n;
  while (cin >> n) {
    ll ans = 0;
    while (prime[ans] <= n && ans < length) {
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) {
  prime[length] = p;
  length++;
  return;
}
int main() {
  insert(2);
  for (ll i = 3; i < 1000000; i += 2) {
    for (ll j = 0; j < length; j++)
      if (i % prime[j] == 0)
        goto cont;
      else if (prime[j] > sqrt(i))
        break;
    insert(i);
  cont:;
  }
  ll n;
  while (cin >> n) {
    ll ans = 0;
    while (prime[ans] <= n) {
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int p[1000010];

int main() {
  int n;
  int count;

  // エラトステネスの篩
  // 素数のリストをつくる
  for (int i = 0; i <= 1000000; i++)
    p[i] = 1;
  p[0] = p[1] = 0;
  for (int i = 2; i * i <= 1000000; i++) {
    if (p[i] == 1) {
      for (int j = 2; i * j <= 1000000; j++) {
        p[i * j] = 0;
      }
    }
  }

  // 素数のカウント
  while (cin >> n) {
    count = 0;
    for (int i = 0; i <= n; i++) {
      if (p[i] == 1)
        count++;
    }
    cout << count << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int count;
  int ans;

  while (cin >> n) {
    ans = 0;
    for (int i = 2; i <= n; i++) {
      count = 0;
      for (int j = 2; j < i; j++) {
        if (i % j == 0) {
          count++;
        }
      }
      if (count == 0)
        ans++;
    }
    cout << ans << endl;
  }

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

#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  while (cin >> n) {
    int p[n + 1];
    for (int i = 0; i < n + 1; i++) {
      p[i] = 1;
    }
    p[0] = 0;
    p[1] = 0;
    for (int i = 2; i <= sqrt(n); i++) {
      for (int j = 2; i * j <= n; j++) {
        p[i * j] = 0;
      }
    }
    int c = 0;
    for (int i = 0; i <= n; i++) {
      if (p[i] == 1) {
        c++;
      }
    }
    cout << c << endl;
  }
}


Error: TLE

Fixed submission:

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

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

#define N 1000000L
bool num[N];

void furui(void) {
  long int i;
  int divide;
  int rt = 1000;
  for (i = 0L; i < N; i++) {
    num[i] = true;
  }
  num[0L] = false;
  num[1L] = false;
  for (divide = 2; divide <= rt; divide++) {
    if (num[divide] == false)
      continue;
    for (i = (long int)divide; i < N; i += divide) {
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void) {
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for (j = 0; j < 30; j++) {
    for (i = 0; (c = getchar()) != EOF; i++) {

      if (c == '\\n') {
        buf[i] = '\\0';
        break;
      }
      buf[i] = c;
    }
    if (c == EOF)
      break;
    n = atol(buf);
    count = 0L;
    for (k = 1L; k <= n; k++) {
      if (num[k] == true)
        count++;
    }
    std::cout << count << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define N 999999
bool num[N];

void furui() {
  long int i;
  int divide;
  int rt = (int)sqrt(N);
  for (i = 0L; i < N; i++) {
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for (divide = 2; divide <= rt; divide++) {
    if (num[divide] == false)
      continue;
    for (i = 0; i < N; i++) {
      if (i % divide == 0) {
        num[i] = false;
      }
    }
    num[divide] = true;
  }
}

int main(void) {
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for (j = 0; j < 30; j++) {
    for (i = 0;; i++) {
      c = getchar();
      if (c == EOF || c == '\\n') {
        buf[i] = '\\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for (k = 1L; k <= n; k++) {
      if (num[k] == 1)
        count++;
    }
    printf("%ld\\n", count);
    if (c == EOF)
      break;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define REP(i, n) for (unsigned int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define MAX 1000001

bool N[MAX] = {};

int M[MAX] = {};

void SoE() {
  REP(i, MAX) N[i] = true;

  N[1] = true;
  for (unsigned int i = 2; i * i <= MAX; i++) {
    for (unsigned int j = i + i; j < MAX; j += i) {
      N[j] = false;
    }
  }
}

void Count() {
  M[1] = 0;
  FOR(i, 2, MAX - 1) {
    int add = 0;
    if (N[i] == true) {
      add = 1;
    }
    M[i] = M[i - 1] + add;
  }
}

int main() {
  SoE();
  Count();
  int tmp;
  while (cin >> tmp) {
    cout << M[tmp] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define REP(i, n) for (unsigned int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define MAX 100001

bool N[MAX] = {};

int M[MAX] = {};

void SoE() {
  REP(i, MAX) N[i] = true;

  N[1] = true;
  for (unsigned int i = 2; i * i <= MAX; i++) {
    for (unsigned int j = i + i; j < MAX; j += i) {
      N[j] = false;
    }
  }
}

void Count() {
  M[1] = 0;
  FOR(i, 2, MAX - 1) {
    int add = 0;
    if (N[i] == true) {
      add = 1;
    }
    M[i] = M[i - 1] + add;
  }
}

int main() {
  SoE();
  Count();
  int tmp;
  while (cin >> tmp) {
    cout << M[tmp] << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int n, k, s = 1, sosuu[100010] = {2};
  for (int i = 3; i <= 999999; i += 2) {
    k = 0;
    for (int j = 3; j <= sqrt(i); j += 2) {
      if (i % j == 0) {
        k = 1;
        break;
      }
    }
    if (k == 0) {
      sosuu[s] = i;
      s++;
    }
  }
  while (cin >> n) {
    int a = 0;
    for (a = 0; sosuu[a] <= n; a++) {
      if (sosuu[a] == 999983) {
        a++;
        break;
      }
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, k;
  while (cin >> n) {
    int num = 0;
    if (n == 1)
      cout << num << endl;
    else {
      for (int i = 3; i <= n; i += 2) {
        k = 0;
        for (int j = 3; j <= sqrt(i); j += 2) {
          if (i % j == 0) {
            k = 1;
            break;
          }
        }
        if (k == 0)
          num++;
      }
      cout << num + 1 << endl;
    }
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

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

int p[MAX];

int main() {
  int counter = 0;
  p[1] = 0;
  for (int i = 2; i < MAX; i++) {
    int sqrti = (int)sqrt(i);
    counter++;
    p[i] = counter;
    for (int j = 2; j <= sqrti; j++) {
      if (i % j == 0) {
        counter--;
        p[i] = counter;
        break;
      }
    }
  }
  int n;
  while (cin >> n) {
    cout << p[n] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int p[MAX];

int main() {
  int counter = 0;
  p[1] = 0;
  for (int i = 2; i < MAX; i++) {
    int sqrti = (int)sqrt(i);
    counter++;
    p[i] = counter;
    for (int j = 2; j <= sqrti; j++) {
      if (i % j == 0) {
        counter--;
        p[i] = counter;
        break;
      }
    }
  }
  int n;
  while (cin >> n) {
    cout << p[n] << endl;
  }
  return 0;
}