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

#include <cstdio>
#include <string.h>
using namespace std;
int pNum;
bool IsPrime[1000010];
int Prime[1000010];
int GetPrime(int n) {
  memset(IsPrime, true, sizeof(IsPrime));
  IsPrime[0] = IsPrime[1] = false;
  pNum = 0;
  for (int i = 2; i <= n; i++) {
    if (IsPrime[i])
      Prime[++pNum] = i;
    for (int j = 1; j <= pNum && Prime[j] * i <= n; j++) {
      IsPrime[Prime[j] * i] = false;
      if (i % Prime[j] == 0)
        break;
    }
  }
  return pNum;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    printf("%d\\n", GetPrime(n));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <string.h>
using namespace std;
int pNum;
bool IsPrime[1000010];
int Prime[1000010];
int GetPrime(int n) {
  memset(IsPrime, true, sizeof(IsPrime));
  IsPrime[0] = IsPrime[1] = false;
  pNum = 0;
  for (int i = 2; i <= n; i++) {
    if (IsPrime[i])
      Prime[++pNum] = i;
    for (int j = 1; j <= pNum && Prime[j] * i <= n; j++) {
      IsPrime[Prime[j] * i] = false;
      if (i % Prime[j] == 0)
        break;
    }
  }
  return pNum;
}
int main() {
  int n;
  while (scanf("%d", &n)) {
    printf("%d\\n", GetPrime(n));
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include "iostream"
#include "string.h"
using namespace std;
bool visit[1000000];
int prime[1000000];

void isPrime() {
  int j = 0;
  for (int i = 2; i < 1000000; i++) {
    if (visit[i])
      prime[j++] = i;
    for (int t = 0; t < j && i * prime[t] < 1000000; t++) {
      visit[i * prime[t]] = false;
      if (i % prime[t] == 0)
        break;
    }
  }
}

int main() {
  int N = 30;
  int n;
  memset(visit, true, 1000000);
  visit[0] = visit[1] = false;
  isPrime();
  while (cin >> n) {
    int cnt = 0;
    for (int i = 2; i <= n; i++)
      if (visit[i])
        cnt++;
    cout << cnt << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
const long long int N = 1000000;
vector<int> prime;
bool arr[N];
void init() {
  memset(arr, true, sizeof(arr));
  arr[0] = arr[1] = false;
  for (int i = 2; i < N; ++i) {
    if (arr[i])
      prime.push_back(i);
    for (int j = 0; j < prime.size() && i * prime[j] < N; j++) {
      arr[i * prime[j]] = false;
      if (i % prime[j] == 0)
        break;
    }
  }
}
int main() {
  int n;
  init();
  while (scanf("%d", &n) != EOF) {
    int j = 0;
    for (; prime[j] <= n; j++)
      ;
    printf("%d\\n", j);
  }
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
#define LIM 999999
using namespace std;
long long int i, j, a, odd;
bool prime[LIM];
long long int arr[999999];
void sieve() {

  arr[a++] = 2;
  for (i = 3; i <= LIM; i += 2) {
    if (!prime[i]) {
      arr[a++] = i;
      if (i * i <= LIM) {
        odd = i;

        for (j = i * i; j <= LIM; j = i * odd) {
          prime[j] = true;
          odd += 2;
        }
      }
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  sieve();
  long long int k, num, count = 0;
  k = 0;
  while (scanf("%lld", &num) != EOF) {
    k = 0;
    count = 0;

    for (int i = 1; i <= num; i++) {
      if (i == arr[k]) {
        count++;
        k++;
      }
    }
    printf("%lld\\n", count);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define LIM 999999
using namespace std;
long long int i, j, a, odd;
bool prime[LIM];
long long int arr[999999];
void sieve() {

  arr[a++] = 2;
  for (i = 3; i <= LIM; i += 2) {
    if (!prime[i]) {
      arr[a++] = i;
      if (i * i <= LIM) {
        odd = i;

        for (j = i * i; j <= LIM; j = i * odd) {
          prime[j] = true;
          odd += 2;
        }
      }
    }
    if (a == 999999)
      break;
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  sieve();
  long long int k, num, count = 0;
  k = 0;
  while (scanf("%lld", &num) != EOF) {
    k = 0;
    count = 0;

    for (int i = 1; i <= num; i++) {
      if (i == arr[k]) {
        count++;
        k++;
      }
    }
    printf("%lld\\n", count);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void getprime() {
  /*int tt=0,flag;
  prime[tt++]=2;
  for(int i=3;i<=1000000;i++)
  {
          flag=1;
          for(int j=0;prime[j]*prime[j]<=i;j++)
          {
                  if(i%prime[j]==0)
                  {
                      flag=0;
                  break;
                  }
          }
          if(flag==1) prime[tt++]=i;
  }*/
  memset(prime, 0, sizeof(prime));
  for (int i = 2; i <= 10000007; i++) {
    if (!prime[i])
      prime[++prime[0]] = i;
    for (int j = 1; j <= prime[0] && prime[j] < 10000007 / i; j++) {
      prime[prime[j] * i] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}

int main() {
  getprime();
  while (cin >> n) {
    for (int i = 1;; i++) {
      if (prime[i] > n) {
        printf("%d\\n", i - 1);
        break;
      }
    }
  }
}


Error: TLE

Fixed submission:

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

void getprime() {
  /*int tt=0,flag;
  prime[tt++]=2;
  for(int i=3;i<=1000000;i++)
  {
          flag=1;
          for(int j=0;prime[j]*prime[j]<=i;j++)
          {
                  if(i%prime[j]==0)
                  {
                      flag=0;
                  break;
                  }
          }
          if(flag==1) prime[tt++]=i;
  }*/
  memset(prime, 0, sizeof(prime));
  for (int i = 2; i <= 1000000; i++) {
    if (!prime[i])
      prime[++prime[0]] = i;
    for (int j = 1; j <= prime[0] && prime[j] < 1000000 / i; j++) {
      prime[prime[j] * i] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}

int main() {
  getprime();
  while (scanf("%d", &n)) {
    for (int i = 1;; i++) {
      if (prime[i] > n) {
        printf("%d\\n", i - 1);
        break;
      }
    }
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
// #define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
#define MEM(x, y) memset(x, y, sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
vector<int> vec;
int a[999999 + 10];
void init() {
  memset(a, 0, sizeof a);
  for (int i = 2; i <= 999999 + 9; ++i) {
    if (a[i] == 0) {
      vec.push_back(i);
      for (int j = i + i; j <= 999999 + 9; j += i) {
        a[j] = 1;
      }
    }
  }
}
int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  int n;
  init();
  while (scanf("%d", &n) != EOF) {
    int ans = upper_bound(vec.begin(), vec.end(), n) - vec.begin();
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <iostream>
using namespace std;
int n;
bool isPrime(int a) {
  int i;
  for (i = 2; i < a; ++i) {
    if (a % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  while (cin >> n) {
    for (int i = 2; i <= n; ++i) {
      if (isPrime(i))
        cout << i << endl;
    }
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

bool p[1000001];
int pn[1000001];

int main() {
  for (int i = 0; i < 1000001; i++) {
    p[i] = true;
  }
  for (int i = 2; i <= 1000000; i++) {
    if (!p[i])
      continue;
    for (int j = 2; i * j <= 1000000; j++) {
      p[i * j] = false;
    }
  }
  int result = 0;
  for (int i = 2; i < 1000001; i++) {

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

Error: TLE

Fixed submission:

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

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

  return true;
}

int main() {
  int num, i, count;

  while (scanf("%d", &num) == 1) {
    count = 0;
    for (i = 1; i <= num; i++) {

      if (isPrime(i))
        count++;
    }
    printf("%d\\n", count);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  long n;
  int a;
  while (scanf("%d", &n) != EOF) {
    vector<bool> p;
    for (int i = 0; i <= n; i++)
      p.push_back(true);
    p[0] = false;
    p[1] = false;
    for (int i = 2; i < sqrt(n) + 1; i++) {
      if (p[i]) {
        for (int j = 0; i * (j + 2) <= n; j++) {
          p[i * (j + 2)] = false;
        }
      }
    }
    int count = 0;
    for (int i = 2; i <= n; i++) {
      if (p[i])
        count++;
    }
    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

const int n = 1000000 + 10;
const int maxn = 1000000 + 10;
int prime[maxn], vis[maxn];
int init() {
  int c = 0, m;
  memset(vis, 0, sizeof(vis));
  m = sqrt(n + 0.5);
  for (int i = 2; i <= m; i++) {
    if (!vis[i]) {
      for (int j = i * i; j <= n; j += i)
        vis[j] = 1;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (!vis[i])
      prime[c++] = i;
  }
  return c;
}

int main() {
  int N;
  int k = init();
  while (~scanf("%d", &N)) {
    int ans = upper_bound(prime, prime + k, N) - prime;
    printf("%d\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long LL;
using namespace std;
#define REPF(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define CLEAR(a, x) memset(a, x, sizeof a)
const int N = 1e7;
int sum[N], vis[N];
void initPrime() {
  int num = 0, m = sqrt(N + 0.5);
  for (int i = 2; i <= m; ++i)
    if (vis[i] == 0)
      for (int j = i * i; j <= N; j += i)
        vis[j] = 1;
  sum[1] = 0;
  for (int i = 2; i <= N; i++) {
    if (!vis[i])
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1];
  }
  //    for(int i=2;i<=10;i++)
  //        cout<<"233  "<<sum[i]<<endl;
}
int main() {
  int n;
  initPrime();
  while (~scanf("%d", &n))
    printf("%d\\n", sum[n]);
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define MAX 1000000
typedef long long int ll;

using namespace std;

bool isprime[MAX];
int prime[MAX];

void sieve() {
  isprime[1] = 1;
  for (int i = 2; i <= sqrt(MAX); i++) {
    if (!isprime[i]) {
      for (int j = i * i; j <= MAX; j += i) {
        isprime[j] = true;
      }
    }
  }
  int count = 0;
  for (int k = 1; k <= MAX; k++) {
    if (!isprime[k])
      prime[k] = ++count;
    else
      prime[k] = count;
  }
}

int main() {
  sieve();
  int n;
  while (scanf("%d", &n) == 1) {
    printf("%d\\n", prime[n]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long in, out;
  int p, count;

  do {
    cin >> in;
    out = 0;

    for (int i = 1; i <= in; i++) {
      count = 0;
      for (p = 1; p <= i; p++) {
        if (i % p == 0) {
          count++;
        }
      }

      if (count == 2) {
        out++;
      }
    }

    cout << out << endl;

  } while (in);

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

#include <math.h>
#include <stdio.h>
#include <string.h>
#define range 1000000
int total_added = 4;
struct primes {
  int key;
  int counts;
};
primes p[range];
bool is_prime(int key) {
  int i;
  for (i = 2; i <= sqrt(key); i++) {
    if (key % i == 0)
      return false;
  }
  return true;
}
void init() {
  p[0].key = 2;
  p[0].counts = 1;
  p[1].key = 3;
  p[1].counts = 2;
  p[2].key = 5;
  p[2].counts = 3;
  p[3].key = 7;
  p[3].counts = 4;
  int i;
  for (i = 8; i <= range; i++) {
    if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0) {
      if (is_prime(i)) {
        p[total_added].key = i;
        p[total_added].counts = p[total_added - 1].counts + 1;
        total_added++;
      }
    }
  }
}
int counting_result(int key) {
  for (int i = total_added - 1; i >= 0; i--) {
    if (key >= p[i].key)
      return p[i].counts;
  }
  return 0;
}

int main() {
  init();
  int i = 0, n;
  while (scanf("%d", &n) == 1 && 30) {

    printf("%d\\n", counting_result(n));
    i++;
  }
}

Error: TLE

Fixed submission:


#include <stdio.h>
int main() {
  int a, N, M, sum = 0, i, j, count = 0, flag = 0;
  while (scanf("%d", &M) != EOF) {
    for (i = 2; i <= M; i++) {
      flag = 0;

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

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

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

const int maxn = 999999 + 10;
bool is_prime[maxn];
int tot[maxn];

void sieve(int n) {
  fill(is_prime, is_prime + n + 1, true);
  is_prime[0] = is_prime[1] = false;

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

int main() {
  //	freopen("data/in.txt", "r", stdin);

  sieve(maxn - 1);
  int cnt = 0;
  for (int i = 0; i < maxn; i++) {
    if (is_prime[i])
      cnt++;
    tot[i] = cnt;
  }

  int n;
  while (1 == scanf("%d", &n)) {
    printf("%d\\n", tot[n]);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
const int MAX_N = 99999;
bool is_prime[MAX_N + 1];

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

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    printf("%d\\n", sieve(n));
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool prime[1000000];

int main() {
  int i, j, k, l, m, n;
  int count;
  while (cin >> n) {
    memset(prime, 0, sizeof(prime));
    prime[1] = 1;
    prime[2] = 0;

    count = 0;

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

Error: TLE

Fixed submission:

#include "iostream"
#include "stdio.h"
using namespace std;

int main() {
  int n, count = 0, m = 0, i, j;
  while (cin >> n) {
    for (i = 2; i <= n; i++) {
      for (j = 1; j < i; j++) {
        if (i % j == 0)
          count++;
      }

      if (count == 1)
        m++;

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

#include <fstream>
#include <iostream>

using namespace std;

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

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

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

int main() {

#if 0
        ifstream cin("34870.in");
#endif

  int *memo = new int[1000001];
  init(memo);

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

  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
int main() {
  long long int LAST;
  while (scanf("%lld", &LAST) == 1) {
    long long int num, i, count = 0, is_prime;
    for (num = 3; num <= LAST; num += 2) {
      is_prime = 1;
      for (i = 2; is_prime && i <= num / 2; i++) {
        is_prime = (num % i != 0);
      }
      count += (is_prime ? 1 : 0);
    }

    printf("%lld\\n", count + 1);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  unsigned int n;
  while (cin >> n) {
    bool *prime = new bool[n + 2];
    unsigned int k, allprime = 0;

    memset(prime, false, n + 2);
    prime[2] = true;
    for (int i = 3; i <= n; i++) {
      if (i % 2 == 0) {
        prime[i] = false;
      } else {
        prime[i] = true;
      }
    }
    k = sqrt(n);
    for (int i = 3; i <= k; i++) {
      for (int j = i + i; j <= n; j += i) {
        prime[j] = false;
      }
    }
    for (int i = 2; i <= n; i++) {
      if (prime[i]) {
        allprime++;
      }
    }
    cout << allprime << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int count = 0;
    for (int prime = 2; prime <= n; prime++) {
      if (prime == 2) {
        count++;
      } else {
        int i;
        for (i = 2; i < prime; i++) {
          if (prime % i == 0)
            break;
        }
        if (i == prime)
          count++;
      }
    }
    printf("%d\\n", count);
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

bool mark[1000000];
void init() {
  for (int i = 0; i < 1000000; i++)
    mark[i] = false;

  mark[0] = true;
  mark[1] = true;
  for (int i = 2; i < 1000000; i++) {
    if (mark[i])
      continue;
    for (int j = i * 2; j < 1000000; j += i) {
      mark[j] = true;
    }
  }
}
int main() {
  init();
  int n, count = 0;
  // if(freopen("D:\\\\test.txt", "r", stdin) == NULL) return -1;
  while (scanf("%d", &n) != EOF) {
    for (int i = 2; i <= n; i++) {
      if (!mark[i]) {
        count++;
      }
    }
    printf("%d\\n", count);
    count = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int Sum_of_Prime(int n);
bool isPrime(int n);
int main() {
  int N;
  while (cin >> N) {
    cout << Sum_of_Prime(N) << endl;
  }
  return 0;
}
int Sum_of_Prime(int n) {
  int p = 1;
  if (n < 2)
    return 0;
  for (int j = 3; j <= n; j += 2) {
    if (isPrime(j))
      p++;
  }
  return p;
}

bool isPrime(int n) {
  if (n < 2)
    return false;
  if (n == 2)
    return true;
  for (int i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return false;
  return true;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define eps 1e-8
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) (a < b ? a : b)
#define ll long long
#define INF 9223372036854775807
int prime[1000005];
bool isprime[10000005];
int num;
int main() {
  for (int i = 2; i < 1000005; i++) {
    if (isprime[i])
      continue;
    prime[num++] = i;
    for (int j = 2 * i; j < 1000005; j += i) {
      isprime[j] = 1;
    }
    //        if(i<100)
    //            printf("%d\\n",prime[num-1]);
  }
  int n;
  while (scanf("%d", &n) != EOF) {
    int ans = upper_bound(prime, prime + num, n) - prime;
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(int argc, char *argv[]) {
  int n;
  int judge(int s);
  while (scanf("%d", &n) != EOF) {
    int count = 0;
    for (int i = 2; i <= n; i++) {
      if (judge(i))
        count++;
    }
    printf("%d\\n", count);
  }
  return 0;
}
int judge(int s) {
  for (int i = 2; i < s; i++) {
    if (s % i == 0)
      return 0;
  }
  return true;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int vis[1000000];
int n;
int sum;
void pre() {
  memset(vis, 0, sizeof(vis));
  for (int i = 2; i <= 999999; i++)
    for (int j = i * 2; j <= 999999; j += i)
      vis[j] = 1;
}
int main() {
  pre();
  while (scanf("%d", &n) != EOF) {
    sum = 0;
    for (int i = 2; i <= n; i++) {
      if (!vis[i])
        sum++;
    }
    printf("%d\\n", sum);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int number = 0;
  int result = 0;
  while (1) {
    result = 1;
    cin >> number;
    if (number == 1 || number == 0)
      result = 0;
    else {

      for (int i = number; i > 2; i--)
        if (i % 2 != 0) {
          int f = 0;
          for (int j = 2; j <= sqrt(i); j++)
            if (i % j == 0) {
              f = 1;
              break;
            }
          if (f == 0)
            result++;
        }
    }
    cout << result << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#define size 1000000
int a[size], c[size];
void seive() {
  int i, j;
  // for(i=0;i<size;i++)    a[i]=1;    a[0]=a[1]=0;
  for (i = 4; i < size; i += 2)
    a[i] = 1;
  for (i = 3; i * i < size; i += 2) {
    if (!a[i]) {
      for (j = i * i; j < size; j += 2 * i)
        a[j] = 1;
    }
  }
}

int main() {
  seive();
  int i, n = 0, x;
  for (i = 2; i < size; i++) {
    if (!a[i]) {
      n++;
    }
    c[i] = n;
  }
  while (scanf("%d", &x) == 1) {
    printf("%d\\n", c[x]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
int main() {
  long long int n, i, j, k, l, number[1000000];

  while (scanf("%lld", &n) != EOF) {
    if (n == 0 || n == 1)
      printf("0\\n");
    else if (n == 2)
      printf("1\\n");
    else if (n == 3)
      printf("2\\n");
    else {
      k = sqrt(n);
      l = 1;
      for (i = 0; i < n; i++) {
        number[i] = i + 1;
      }

      for (j = 2; j <= k; j++) {
        for (i = 1; i < n; i++) {
          if (number[i] % j == 0) {
            number[i] = 0;
          }
        }
      }
      for (i = 1; i < n; i++) {
        if (number[i] != 0)
          l++;
      }
      printf("%lld\\n", l);
    }
  }
  return 0;
}