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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int n;
  int nums[100000] = {0};
  while (cin >> n) {
    int count = 0;
    int qf = 0;
    int qe = 0;
    for (int i = 2; i <= n; i++) {
      bool f = false;
      for (int qe = 0; qe < qf; qe++) {
        if (i < nums[qe] * nums[qe])
          break;
        if (i % nums[qe] == 0) {
          f = true;
          break;
        }
      }
      if (!f) {
        count++;
        nums[qf] = i;
        qf++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int n;
  int nums[100000] = {0};
  while (cin >> n) {
    int count = 0;
    int qf = 0;
    int qe = 0;
    for (int i = 2; i <= n; i++) {
      bool f = false;
      for (int qe = 0; qe < qf; qe++) {
        if (i % nums[qe] == 0) {
          f = true;
          break;
        }
      }
      if (!f) {
        count++;
        nums[qf] = i;
        qf++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

int CountPrime(int n) {

  if ((n == 0) || (n == 1)) {
    return 0;
  } else {
    std::vector<bool> data(n - 1, 1);
    int count = 0;

    for (int i = 2; i <= n; i++) {
      if (data[i - 2] == 1) {
        for (int j = i * 2; j <= n; j += i) {
          data[j - 2] = 0;
        }
      }
    }
    for (int i = 0; i < n - 1; i++) {
      if (data[i] == 1) {
        count++;
      }
    }

    return count;
  }
}

int main() {
  int n;

  while (std::cin >> n) {
    std::cout << CountPrime(n) << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int func(int n) {
  int i, count = 0;

  while (1 < n) {
    for (i = 2; i < n; i++) {
      if (n % i == 0) {
        break;
      }
    }
    if (i == n) {
      count++;
    }
    n--;
  }
  return count;
}

int main() {
  int input;

  while (std::cin >> input) {
    std::cout << func(input) << "\\n";
  }

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

#include <iostream>
using namespace std;

int main() {
  int n;
  int sosu[100000];
  int snum;
  bool judge;

  sosu[0] = 2;

  while (cin >> n) {
    snum = 0;
    for (int i = 3; i <= n; i++) {
      judge = true;
      for (int j = 0; sosu[j] * sosu[j] <= i; j++) {
        if (i % sosu[j] == 0) {
          judge = false;
          break;
        }
      }
      if (judge == true) {
        snum++;
        sosu[snum] = i;
      }
    }
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << snum + 1 << endl;
    }
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int sosu[100000];
  int snum;
  bool judge;

  sosu[0] = 2;

  while (cin >> n) {
    snum = 0;
    for (int i = 3; i <= n; i++) {
      judge = true;
      for (int j = 0; j <= snum; j++) {
        if (i % sosu[j] == 0) {
          judge = false;
          break;
        }
      }
      if (judge == true) {
        snum++;
        sosu[snum] = i;
      }
    }
    cout << snum + 1 << endl;
  }

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

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

int main() {
  long int n, m;
  while (cin >> n) {
    vector<int> number(1000000, 0);
    int ans = 0;

    for (int i = 2; i <= n; i++) {
      if (number[i] == 0) {
        ans++;
        // cout<<i<<endl;
        for (m = i; m <= n; m += i) {
          number[m] = 1;
        }
      }
    }
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long int n, m;
  while (cin >> n) {
    long int i;
    int number[100000000] = {0};
    int ans = 0;

    for (i = 2; i < n; i++) {
      if (number[i] == 0) {
        ans++;
        for (m = i; m < n; m += i) {
          number[m] = 1;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

int prime[1000000];

bool isPrime(int n) {
  int x = sqrt(static_cast<double>(n));
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}

int main() {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0 && ns[i] != 2)
      ns[i]--;
    i++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

int prime[1000000];

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

void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}

int main() {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i]--;
    i++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

//--------------------------------------------------template----------------------------------------//
// c
#include <math.h>
#include <stdio.h>
#include <time.h>
// c++
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// c++11
#include <tuple>
#define all(c) ((c).begin(), (c).end())
#define rall(c) (c).rbegin(), (c).rend()
// #define sort(v,n) sort(v,v+n)
// #define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

bool is_prime(int a) {
  int now = 2;
  while (now * now <= a) {
    if (a % now == 0)
      return 0;
    else
      now++;
  }
  return 1;
}

int main() {
  while (cin >> n) {
    ll ans = 0;
    bool a[1000001];
    for (int i = 0; i < 1000001; i++)
      a[i] = 0;
    for (int i = 2; i <= n; i++) {
      if (a[i] != 1)
        ans++;
      for (int j = i; j <= n; j += i) {
        a[j] = 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

//--------------------------------------------------template----------------------------------------//
// c
#include <math.h>
#include <stdio.h>
#include <time.h>
// c++
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// c++11
#include <tuple>
#define all(c) ((c).begin(), (c).end())
#define rall(c) (c).rbegin(), (c).rend()
// #define sort(v,n) sort(v,v+n)
// #define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

bool is_prime(int a) {
  int now = 2;
  while (now * now <= a) {
    if (a % now == 0)
      return 0;
    else
      now++;
  }
  return 1;
}

int main() {
  while (cin >> n) {
    ll ans = 0;
    bool a[1000001];
    for (int i = 2; i <= n; i++) {
      if (a[i] == 1)
        continue;
      if (is_prime(i))
        ans++;
      else {
        for (int j = i; j <= n; j += i) {
          a[j] = 1;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int i, n, count, num;
  deque<int> sosu;
  deque<int>::iterator it;
  bool flg;

  // テーブルを予め作成する
  bool prime[1000000] = {false};

  prime[2] = true;

  for (i = 3; i <= 1000000; i += 2) {
    flg = true;
    for (it = sosu.begin(); it != sosu.end(); it++) {
      num = *it;
      if (i < num * num) {
        break;
      }
      if ((i % num) == 0) {
        flg = false;
        break;
      }
    }
    if (flg == true) {
      sosu.push_back(i);
      prime[i] = true;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int i, n, count, num;
  deque<int> sosu;
  deque<int>::iterator it;
  bool flg;

  while (cin >> n) {
    sosu.clear();
    if (n <= 2) {
      if (n == 2) {
        count = 1;
      } else
        count = 0;
    } else {
      for (i = 3; i <= n; i += 2) {
        flg = true;
        for (it = sosu.begin(); it != sosu.end(); it++) {
          num = *it;
          if (i < 2 * num) {
            break;
          }
          if ((i % num) == 0) {
            flg = false;
            break;
          }
        }
        if (flg == true) {
          sosu.push_back(i);
        }
      }
      count = sosu.size() + 1;
    }
    cout << count << endl;
  }

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

#include <math.h>
#include <stdio.h>
#define MAX_S 999999

int main(void) {
  int prime_f[MAX_S], prime_sum[MAX_S], sum = 0, n;

  for (size_t i = 0; i < MAX_S; i++) {
    prime_f[i] = 1;
    prime_sum[i] = 0;
  }
  prime_f[0] = 0;

  for (size_t i = 1; i < sqrt(MAX_S); i++) {
    if (prime_f[i] == 1) {
      for (size_t j = i + 1; j * (i + 1) <= MAX_S; j++) {
        prime_f[(i + 1) * j - 1] = 0;
      }
    }
  }

  for (size_t i = 0; i < MAX_S; i++) {
    if (prime_f[i] == 1)
      sum++;
    prime_sum[i + 1] = sum;
  }

  while (scanf("%d", &n) != EOF) {
    printf("%d\\n", prime_sum[n]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
#define N 1000000
int main(void) {
  int prime[N] = {0}, sums[N] = {0}, n, sum = 0;
  prime[1] = 1;
  for (size_t i = 2; i <= sqrt(N); i++) {
    if (prime[i] == 0) {
      sum++;
      sums[i] = sum;
      for (size_t t = i + 1; t <= N; t++) {
        sums[t] = sum;
        if (t % i == 0)
          prime[t] = 1;
      }
    }
  }
  while (scanf("%d", &n) != EOF) {
    printf("%d\\n", sums[n]);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX_N 999999
bool prime_check(int n, int k = 2) {
  if (n < k * k)
    return true;
  if (n % k == 0)
    return false;
  return prime_check(n, k + 1);
}
int main() {
  int n;
  bool isprime[MAX_N + 1];
  for (int i = 2; i <= MAX_N; i++)
    isprime[i] = prime_check(i);
  while (cin >> n) {
    int cnt = 0;
    for (int i = 2; i <= n; i++) {
      if (isprime[i] == true)
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int cnt = 0, res = 0;
    for (int i = 3; i <= n; i += 2) {
      for (int j = 1; j <= i / 2; j++) {
        if (i % j == 0)
          cnt++;
        if (cnt > 1)
          break;
      }
      if (cnt == 1)
        res++;
      cnt = 0;
    }
    cout << res + 1 << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int n;
  int ans;
  char prime[1000000];
  int i, j;
  int p;

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

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

    for (i = 2, p = 0; i <= n + 1; i++) {
      if (prime[i]) {
        for (j = 2 * i; j <= n; j += i) {
          prime[j] = 0;
        }
      }
    }
    for (i = 0, p = 0; i <= n; i++) {
      if (prime[i] == 1) {
        p++;
      }
    }

    ans = p;
    printf("%d\\n", ans);
  }

  return (0);
}

Error: 0

Fixed submission:

#include <stdio.h>

int sieve(int n) {
  char prime[100000];
  int i, j;
  int p;

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

  for (i = 2; i <= n + 1; i++) {
    if (prime[i]) {
      for (j = 2 * i; j <= n; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (i = 0, p = 0; i <= n; i++) {
    if (prime[i] == 1) {
      p++;
    }
  }

  return (p);
}

int main(void) {
  int num;
  int ans;

  while (scanf("%d", &num) != EOF) {
    ans = sieve(num);

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

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

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 999999 + 5;
int prime[maxn];
bool is_prime[maxn];
int sieve(int n) {
  int p = 0;
  fill(is_prime, is_prime + n + 1, true);
  is_prime[0] = is_prime[1] = true;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
  return p;
}

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, j;
  int time_sum = 0;
  int a[100000];
  while (cin >> n) {
    if (time_sum == 29)
      break;
    time_sum = time_sum + 1;
    int sum = 0;
    for (i = 2; i <= n; i++)
      a[i] = 1;
    for (i = 2; i <= n; i++) {
      if (a[i])
        for (j = i + i; j <= n; j = j + i)
          a[j] = 0;
    }
    for (i = 2; i <= n; i++) {
      if (a[i])
        sum = sum + 1;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
  int prime_num[1000001];
  memset(prime_num, 0, 1000001);
  prime_num[2] = 1;
  int ans = 1;
  for (int i = 3; i <= 1000000; i++) {
    if (i % 2 == 0) {
      prime_num[i] = prime_num[i - 1];
      continue;
    }
    bool is_prime = true;
    for (int j = 3; j * j <= i; j++) {
      if (i % j == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime) {
      prime_num[i] = prime_num[i - 1] + 1;
    } else {
      prime_num[i] = prime_num[i - 1];
    }
  }
  int n;
  while (cin >> n) {
    cout << prime_num[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef long long ll;

int main() {
  int n;
  while (cin >> n) {
    int ans = 1;

    for (int i = 3; i <= n; i += 2) {
      bool isPrime = true;
      for (int j = 3; (j * j) <= i; j += 2) {
        if (i % j == 0) {
          isPrime = false;
          break;
        }
      }
      if (isPrime)
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  const int num = 1000000;
  vector<int> pnums(num);
  vector<bool> np(num);
  np[0] = np[1] = true;

  for (int i = 2; i < num; ++i) {
    pnums[i] = pnums[i - 1] + !np[i];

    if (!np[i]) {
      for (int j = i; j < num; j += i) {
        np[j] = true;
      }
    }
  }

  for (int n; cin >> n;)
    cout << pnums[n] << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  const int num = 100000;
  vector<int> pnums(num);
  vector<bool> np(num);
  np[0] = np[1] = true;

  for (int i = 2; i < num; ++i) {
    pnums[i] = pnums[i - 1] + !np[i];

    if (!np[i]) {
      for (int j = i; j < num; j += i) {
        np[j] = true;
      }
    }
  }

  for (int n; cin >> n;)
    cout << pnums[n] << endl;

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

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

int primes[1000000] = {0};

int main() {
  primes[0] = -1;
  primes[1] = -1;
  for (int i = 2; i < 1000; i++) {
    if (primes[i] == -1)
      continue;
    for (int j = i + 1; j < 1000000; j++) {
      if (j % i == 0)
        primes[j] = -1;
    }
  }
  int n;
  while (-1 != scanf("%d", &n)) {
    int ans = 0;
    for (int i = 2; i <= n; i++) {
      if (primes[i] == 0)
        ans++;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

using namespace std;
vector<int> prime;

int calc(int);

int main() {
  int n;
  prime.push_back(2);
  while (-1 != scanf("%d", &n)) {
    cout << calc(n) << endl;
  }
  return 0;
}

int calc(int n) {
  int lastPrime = prime[prime.size() - 1];
  if (n > lastPrime) {
    for (int i = lastPrime; i <= n; i++) {
      bool isPrime = true;
      for (int j = 0; j < prime.size(); j++) {
        int checkPrime = prime[j];
        if (i % checkPrime == 0) {
          isPrime = false;
          continue;
        }
      }
      if (isPrime)
        prime.push_back(i);
    }
    return prime.size();
  } else {
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] >= n) {
        return i;
      }
    }
  }
  return -1;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  int sum[1000000];
  sum[0] = 0;
  sum[1] = 0;
  sum[2] = 1;
  for (int i = 3; i < 1000000; i++) {
    sum[i] = sum[i - 1];
    if (IsPrime(i))
      sum[i]++;
  }
  while (cin >> n)
    cout << sum[n] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  while (cin >> n) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
      if (IsPrime(i))
        count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX_SIZE (1000000)

int prime[MAX_SIZE];

int main() {
  int n;

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

  for (int i = 2; i < MAX_SIZE; i++) {
    prime[i] = 1;
  }

  // Sieve of Eratosthenes
  for (int i = 2; i * i < MAX_SIZE; i++) {
    if (prime[i]) {
      for (int j = i * i; j < MAX_SIZE; j += i) {
        prime[j] = 0;
      }
    }
  }

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

  while (scanf("%d", &n) != EOF) {
    printf("%d\\n", prime[n]);
  }

  return (0);
}

Error: TLE

Fixed submission:

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

#define MAX_SIZE (1000000)

int prime[MAX_SIZE];

int main() {
  int n;

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

  for (int i = 2; i < MAX_SIZE; i++) {
    prime[i] = 1;
  }

  for (int i = 0; i < MAX_SIZE; i++) {
    for (int j = i * i; j < MAX_SIZE; j += i) {
      prime[j] = 0;
    }
  }

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

  while (scanf("%d", &n) != EOF) {
    printf("%d\\n", prime[n]);
  }

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

#include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V + 1];
int main() {
  int i, k;
  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;
      }
    }
  }

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

Error: 0

Fixed submission:

#include <stdio.h>
const int MAX_V = 100;
int prime[MAX_V + 1];
int main() {
  int i, k;
  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;
      }
    }
  }

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

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

vector<char> sieve(const int M) {
  vector<char> isPrime(M);
  for (int i = 2; i < M; i++)
    isPrime[i] = true;
  for (int i = 2; i * i < M; i++) {
    if (not isPrime[i])
      continue;
    for (int j = i * i; j < M; j += i) {
      isPrime[j] = false;
    }
  }
  return isPrime;
}

int main(int argc, char const *argv[]) {
  int n;
  vector<char> p;
  while (cin >> n) {
    int count = 0;
    p = sieve(n + 1);
    for (vector<char>::iterator it = p.begin(); it != p.end(); ++it) {
      if (*it == true)
        ++count;
    }

    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int IsPrime(int n) {
  int i;

  for (i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return 0;
  return 1;
}

int main() {
  int in;

  while (scanf("%d", &in) != EOF) {
    int c = 0;

    for (int i = 3; i < in; i += 2)
      if (IsPrime(i) == 1)
        ++c;

    if (in >= 2)
      ++c;

    cout << c << endl;
  }

  return 0;
}