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

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

using namespace std;

int pn(int num) {

  if (num == 2 || num == 3 || num == 5)
    return 1;
  if (num < 2 || num % 2 == 0)
    return 0;

  int i = 3;
  while (i <= sqrt(num)) {
    if (num % i == 0)
      return 0;
    i += 2;
  }
  return 1;
}

int main() {

  int n;
  int num;
  int cnt = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    cnt += pn(num);
  }

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int pn(int num) {

  if (num == 2 || num == 3 || num == 5)
    return 1;
  if (num < 2 || num % 2 == 0)
    return 0;

  int i = 3;
  while (i < num - 1) {
    if (num % i == 0)
      return 0;
    i += 2;
  }
  return 1;
}

int main() {

  int n;
  int num;
  int cnt = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    cnt += pn(num);
  }

  cout << cnt << endl;

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

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

bool isPrime(int x);

int main() {
  int N, x, cnt = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (isPrime(x)) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

bool isPrime(int x) {
  bool prime = false;
  int i = 3;
  if (x == 1) {
  } else if ((x == 2) || (x == 3)) {
    prime = true;
  } else if ((x % 2) == 0) {
  } else {
    while (i < x) {
      if ((x % i) == 0) {
        break;
      } else if (i > sqrt(x)) {
        prime = true;
        break;
      }
      i = i + 2;
    }
  }
  return prime;
}

Error: WA

Fixed submission:

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

int isPrime(long x);

int main() {
  long N, x;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    isPrime(x);
  }
  return 0;
}

int isPrime(long x) {
  bool prime;
  int i;
  if (x == 1) {
    prime = false;
  } else if (x == 2) {
    prime = true;
  } else if ((x % 2) == 0) {
    prime = false;
  } else if ((x % 2) != 0) {
    while (i <= sqrt(x)) {
      if ((x % i) == 0) {
        prime = false;
        break;
      } else {
        prime = true;
      }
      i = i + 2;
    }
  }
  if (prime) {
    cout << x << endl;
  }
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n, cnt = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    long num;
    bool flag = true;

    cin >> num;

    for (int j = 2; j <= (int)sqrt((double)num) && flag == true; j++) {
      if (num % j == 0) {
        flag = false;
        break;
      }
    }

    if (flag == true || num == 2)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, cnt = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    long num;
    bool flag = true;

    cin >> num;

    for (int j = 2; j <= num / 2 && flag == true; j++) {
      if (num % j == 0) {
        flag = false;
        break;
      }
    }

    if (flag == true || num == 2)
      cnt++;
  }

  cout << cnt << endl;

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

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, num;
  int notpr;

  cin >> n;

  notpr = 0;
  for (int i = 0; i < n; i++) {
    cin >> num;
    for (int j = 2; j <= sqrt(num); j++) {
      if (num % j == 0) {
        notpr++;
        break;
      }
    }
  }
  cout << n - notpr << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, num;
  int notpr;

  cin >> n;

  notpr = 0;
  for (int i = 0; i < n; i++) {
    cin >> num;
    for (int j = 2; j < num; j++) {
      if (num % j == 0) {
        notpr++;
        break;
      }
    }
  }
  cout << n - notpr << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;

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

int main() {
  int n, a, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cnt += isP(a);
  }
  cout << cnt << endl;
}

Error: MLE

Fixed submission:

#include <iostream>
#define MAX 100000001
using namespace std;
bool isP[MAX];
void make_table() {
  for (int i = 0; i < MAX; i++)
    isP[i] = true;
  isP[0] = isP[1] = false;
  for (int i = 2; i * i < MAX; i++) {
    if (!isP[i])
      continue;
    for (int j = i * i; j < MAX; j += i) {
      isP[j] = false;
    }
  }
}

int main() {
  make_table();
  int n, a, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cnt += isP[a];
  }
  cout << cnt << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

bitset<100000001> sieve;
void makeSieve() {
  sieve.set();
  sieve[0] = sieve[1] = false;
  for (int i = 4; i < 100000001; i += 2) {
    sieve[i] = false;
  }
  for (int i = 3; i < 10001; i += 2) {
    if (!sieve[i])
      continue;
    for (int j = i * i; j < 100000001; j += i) {
      sieve[j] = false;
    }
  }
}
int main() {
  makeSieve();
  int n;
  cin >> n;
  int num = 0;
  while (n--) {
    int a;
    cin >> a;
    num += (int)sieve[a];
  }
  cout << num << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

bool sieve[100000001];
void makeSieve() {
  fill_n(sieve, 100000001, true);
  sieve[0] = sieve[1] = false;
  for (int i = 4; i < 10001; i += 2) {
    sieve[i] = false;
  }
  for (int i = 3; i < 101; i += 2) {
    if (!sieve[i])
      continue;
    for (int j = i * i; j < 10001; j += i) {
      sieve[j] = false;
    }
  }
}
int main() {
  makeSieve();
  int n;
  cin >> n;
  int num = 0;
  while (n--) {
    int a;
    cin >> a;
    num += (int)sieve[a];
  }
  cout << num << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

bool check(int n) {
  if (n < 2)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;

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

int n[10000];

int main() {
  int sw = 0;
  int a;
  cin >> a;

  for (int i = 0; i < a; i++) {
    cin >> n[i];
  }

  for (int i = 0; i < a; i++) {
    if (check(n[i]))
      sw++;
  }
  cout << sw << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

int n[10000];

int main() {
  int sw = 0;
  int a;
  cin >> a;

  for (int i = 0; i < a; i++) {
    cin >> n[i];
  }

  for (int i = 0; i < a; i++) {
    if (n[i] == 2) {
      sw++;
      continue;
    }
    if (check(n[i]))
      sw++;
  }
  cout << sw << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

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

int main() {
  int n, j, b, sum = 0;
  cin >> n;
  for (j = 0; j < n; j++) {
    cin >> b;
    if (isprime(b))
      sum += 1;
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, i, j, a, b = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    for (j = 3; j < a; j = j + 2) {
      if (a % j == 0)
        break;
      if (a % 2 == 0)
        break;
      if (a % 3 == 0)
        break;
      if (a % 5 == 0)
        break;
      if (a % 7 == 0)
        break;
      if (j == a - 2)
        b++;
    }
    if (a == 2)
      b++;
    if (a == 3)
      b++;
    if (a == 5)
      b++;
    if (a == 7)
      b++;
  }
  cout << b << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

bool is_prime(int num) {
  int a = sqrt(num);

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

    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main(void) {
  int n;
  cin >> n;

  int num;
  int prime_count = 0;
  for (int i = 0; i < n; i++) {
    cin >> num;

    if (is_prime(num) == true) {
      prime_count++;
    }
  }
  cout << prime_count << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

bool is_prime(int num) {
  for (int i = 2; i < num; i++) {

    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main(void) {
  int n;
  cin >> n;

  int num;
  int prime_count = 0;
  for (int i = 0; i < n; i++) {
    cin >> num;

    if (is_prime(num) == true) {
      prime_count++;
    }
  }
  cout << prime_count << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int a[10001];
int main() {
  int n, b, c, m = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1)
      continue;
    else {
      int t = 0;
      b = sqrt(a[i]);
      for (int j = 2; j <= b; j++)
        if (a[i] % j == 0)
          t++;
      if (t == 0)
        m++;
    }
  }
  printf("%d\\n", m);
  return 0;
}

Error: MLE

Fixed submission:

#include <stdio.h>
bool a[100000000 + 1];
int main() {
  a[1] = true;
  int sum = 0;
  int n;
  int k;
  scanf("%d", &n);
  for (int i = 2; i * i <= 100000000; i++) {
    if (a[i] == false) {
      k = i;
      for (int j = 2; k * j <= 100000000; j++)
        a[k * j] = true;
    }
  }
  int c;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c);
    if (!a[c])
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
vector<int> n;

int main(void) {
  int count, temp, ans = 0, rant = 0;

  cin >> count;
  for (int i = 0; i < count; i++) {
    cin >> temp;
    rant = rant > temp ? rant : temp;
    n.push_back(temp);
  }

  vector<bool> pri(++rant, 0);

  for (int i = 2; i * i < rant; i++) {
    if (!pri.at(i)) {

      for (int j = i; j * i < rant; j++) {
        pri[i * j] = true;
      }
    }
  }

  for (int i = 0; i < count; i++) {
    if (!pri.at(n.at(i)))
      ans++;
  }

  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;
vector<int> n;
vector<int> solute(vector<bool> *p) {
  int count = (*p).size();
  for (int i = 2; i * i < count; i++) {
    if (!(*p).at(i)) {

      for (int j = i; j * i < count; j++) {
        (*p)[i * j] = true;
      }
    }
  }
}
int main(void) {
  int count, temp, ans = 0;

  cin >> count;
  for (int i = 0; i < count; i++) {
    cin >> temp;
    n.push_back(temp);
  }
  sort(n.begin(), n.end());
  vector<bool> pri(n.back() + 1, 0);
  solute(&pri);

  for (int i = 0; i < count; i++) {
    if (!pri.at(n.at(i)))
      ans++;
  }

  cout << ans << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
int pr[10000001] = {0};
int main() {
  int i, j, k, s, d, r, n, h, l, x, y, z, g;

  scanf("%d", &g);
  s = 0;
  for (h = 1; h <= g; h++) {
    scanf("%d", &n);

    d = 0;
    r = sqrt(n);
    if (n % 2 == 0)
      d++;
    for (i = 3; i <= r; i += 2) {
      if (n % i == 0)
        d++;
      if (d > 0)
        break;
    }

    if (n == 2)
      s++;

    else if (d == 0)
      s++;
  }
  printf("%d\\n", s);

  return 0;
}

Error: MLE

Fixed submission:

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

int a[100000090];
vector<int> vc;

void sieve() {
  int i, j;
  a[1] = 1;

  vc.push_back(2);

  for (i = 4; i <= 100000030; i += 2)
    a[i] = 1;
  for (i = 3; i <= 100000030; i += 2) {
    if (a[i] == 0) {
      for (j = 3 * i; j <= 100000030; j = j + i * 2)
        a[j] = 1;
      vc.push_back(i);
    }
  }
}
int main()

{
  sieve();
  int i, j, k, l = 0, n;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &k);
    if (a[k] == 0)
      l++;
  }
  printf("%d\\n", l);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

typedef long long ll;

using namespace std;

bool isPrime(int x) {
  if (x == 2)
    return true;
  if (x < 2 || x % 2 == 0)
    return false;

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

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  while (n--) {
    int t;
    cin >> t;

    if (isPrime(t)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int a[9999999];
vector<int> vc;

void sieve() {
  int i, j;
  a[1] = 1;

  vc.push_back(2);

  for (i = 4; i <= 9999997; i += 2)
    a[i] = 1;
  for (i = 3; i <= 9999997; i += 2) {
    if (a[i] == 0) {
      for (j = 3 * i; j <= 9999997; j = j + i * 2)
        a[j] = 1;
      vc.push_back(i);
    }
  }
}
int main()

{
  sieve();
  int i, j, k, l = 0, n;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &k);
    if (a[k] == 0)
      l++;
  }
  printf("%d\\n", l);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
bool f(int n) {
  int cnt = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      cnt++;
  }
  if (cnt == 0)
    return true;
  return false;
}
int main() {
  int n, m, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    if (f(m))
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int a[1000];
int n;
int main() {
  cin >> n;
  int x, cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    int k = 0;
    for (int j = 1; j <= x; ++j)
      if (x % j == 0)
        k++;
    if (k == 2)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int n, k, t = 0;
bool prime(int o) {
  if (o < 2)
    return false;
  for (int i = 2; i * i <= o; i++)
    if (o % i == 0)
      return false;
  return true;
}
int main() {
  cin >> n;
  while (n--) {
    cin >> k;
    if (prime(k))
      t++;
  }
  cout << t << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
string prime(int a) {
  for (int j = 0; j < sqrt(a); j++) {
    if (a % j == 0) {
      return "no";
    }
  }
  return "yes";
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (prime(a[i]) == "yes") {
      cnt++;
    }
  }
  cout << cnt << "\\n";
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

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

int main() {
  int N, n, k = 0;
  scanf("%d", &N);
  while (N--) {
    scanf("%d", &n);
    if (is_prime(n))
      k++;
  }
  printf("%d\\n", k);

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
// #define Kongxiangzhouye
#define sd(x) scanf("%d", &x)
#define ss(x) scanf("%s", x)
#define sc(x) scanf("%c", &x)
#define sf(x) scanf("%f", &x)
#define slf(x) scanf("%lf", &x)
#define slld(x) scanf("%lld", &x)
#define me(x, b) memset(x, b, sizeof(x))
#define pd(d) printf("%d\\n", d);
#define plld(d) printf("%lld\\n", d)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N = 100000;
const int INF = 0x3f3f3f3f;

bool vis[100000000];
int main() {
#ifdef Kongxiangzhouye
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  memset(vis, 0, sizeof(vis));
  int m = sqrt(100000000);
  for (int i = 2; i < m; i++) {
    if (!vis[i])
      for (int j = i * 2; j < 100000000; j = j + i)
        vis[j] = 1;
  }
  int n, a;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!vis[a])
      ans++;
  }
  cout << ans << endl;

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

#include <cmath>
#include <cstdio>
bool isp(int nu) {
  int i = 1;
  if (nu == 1)
    return false;
  else if (nu == 2)
    return 1;
  int sqr = sqrt(nu) + 1;
  for (i = 2; i <= sqr; i++)
    if (nu % i == 0)
      return false;
  return true;
}
int main() {
  short sum = 0, n;
  scanf("%d", &n);
  for (; n > 0; n--) {
    int temp;
    scanf("%d", &temp);
    if (isp(temp))
      sum++;
  }
  printf("%d\\n", sum);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, l, p = 0, q = 0;
  long long k;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> k;
    p = 0;
    for (j = 2; j <= k / 2; j++) {
      if ((k % j) == 0) {
        p = 1;
        break;
      }
    }
    if (p == 0) {
      q++;
    }
  }
  cout << q << '\\n';
  ;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, i, j, pnum = 0;
  int l;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &l);
    for (j = 2; j <= sqrt(l) && (int)l % j != 0; j++)
      ;
    if (j == (int)sqrt(l) + 1 || l == 2 || l == 3 || l == 5 || l == 7)
      pnum++;
  }
  printf("%d\\n", pnum);
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool isPrime(int text) {
  if (text == 1)
    return 0;
  for (int i = 2; i < (text - i) + 1; i++) {
    if (text % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int n; // 测试个数
  cin >> n;
  int nub = 0; // 质数个数
  while (n--) {
    int text;
    cin >> text;
    if (isPrime(text)) {
      nub++;
    }
  }
  cout << nub << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, i, j, x, total = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x == 2)
      total++;
    if (x % 2 != 0) {
      for (j = 3; j <= (double)sqrt(x); j += 2) {
        if (x % j == 0)
          goto a;
      }
      total++;
    a:;
    }
  }
  cout << total << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, i, j, x, total = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x == 2 | x == 3)
      total++;
    for (j = 2; j <= x / 2; j++) {
      if (x % j == 0)
        break;
      if (j == x / 2)
        total++;
    }
  }
  cout << total << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

bool isprime(int x) {
  if (x == 2)
    return true;
  if (x < 2 || x % 2 == 0) {
    return false;
  }

  for (int i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  int num;
  int count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    if (isprime(num))
      count++;
  }

  cout << count << endl;

  return 0;
}

Error: MLE

Fixed submission:

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

unsigned char prime[100000000];
int main() {
  int primeTop;
  int n;
  int num, count = 0;

  for (int i = 0; i < 100000000; i++) {
    prime[i] = '2';
  }
  prime[0] = prime[1] = '0';
  for (int i = 0; i < sqrt(100000000); i++) {
    if (prime[i] == '2') {
      primeTop = i;
      for (int j = 1; primeTop * j < 100000000; j++) {
        prime[j * primeTop] = '0';
      }
      prime[primeTop] = '1';
    }
  }

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    if (prime[num] == '1')
      count++;
  }

  cout << count << endl;

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

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

using namespace std;

int main() {
  int n, num, ans = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    int j = 2;
    if (num == 2 || num == 3)
      ans++;
    else {
      while (j <= (int)sqrt(num)) {

        if ((num % j) == 0)
          break;
        if (j == (int)sqrt(num))
          ans++;

        j++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, num, ans = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    int j = 2;
    if (num == 2)
      ans++;
    else {
      while (j <= num) {
        if (num % j == 0)
          break;
        if (j == num - 1)
          ans++;
        j++;
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

#define PMAX (1e8) + 1

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

  int n, input, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input;
    if (p[input])
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

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

int main() {
  int n, c = 0, v;
  cin >> n;
  int m[n];
  for (int i = 0; i < n; i++) {
    cin >> v;
    if (isPrime(m, v, c)) {
      c++;
      m[c] = v;
    }
  }
  cout << c << endl;
  return 0;
}