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

#include <cstdio>
using namespace std;
int prime[10000];
int p[10000];
int c[10000];
int main() {
  for (int i = 2; i * i < 10000; i++) {
    for (int j = i * i; j < 10000; j += i)
      prime[j] = 1;
  }
  int cnt = 0;
  for (int i = 2; i < 10000; i++) {
    if (prime[i] == 0) {
      p[cnt] = i;
      cnt++;
    }
  }
  int n, q, z = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &n);
    bool OK = true;
    for (int j = 0; j < cnt; j++) {
      if (n < p[j] * p[j])
        break;
      if (n % p[j] == 0)
        OK = false;
    }
    if (OK == true)
      z++;
  }
  printf("%d\\n", z);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
using namespace std;
int prime[10000];
int p[10000];
int main() {
  for (int i = 2; i < 10000; i++) {
    for (int j = i * j; j < 10000; j += i)
      prime[j] = 1;
  }
  int cnt = 0;
  for (int i = 2; i < 10000; i++) {
    if (prime[i] == 0) {
      p[cnt] = i;
      cnt++;
    }
  }
  int n, q, z;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &n);
    bool OK = true;
    for (int j = 0; j < cnt; j++) {
      if (n % p[j] == 0)
        OK = false;
    }
    if (OK == true)
      z++;
  }
  printf("%d\\n", z);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;

int f_primeNumber2(int x) {
  int i;

  for (i = 2; i <= sqrt(x); ++i) {
    if (x % i == 0 && x != i)
      return 1;
  }

  return 0;
}

int main() {
  int n;
  int x[10000];
  int i;
  int c = 0;

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

  for (i = 0; i < n; ++i) {
    if (f_primeNumber2(x[i]) == 1) {
      c = c + 1;
    }
  }
  cout << n - c << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;

class c_primeNumber {
private:
  int n;
  int x[10000];

public:
  void f_primeNumber1();
  int f_primeNumber2(int x);
};

void c_primeNumber::f_primeNumber1() {
  int i;
  int c = 0;

  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> x[i];
    if (c_primeNumber::f_primeNumber2(x[i]) == 1) {
      c = c + 1;
    }
  }
  cout << n - c << endl;
}

int c_primeNumber::f_primeNumber2(int x) {
  int i;

  for (i = 2; i <= (x / 2); ++i) {
    if (x % i == 0)
      return 1;
  }

  return 0;
}

int main() {
  c_primeNumber primeNumber01;

  primeNumber01.f_primeNumber1();

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

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

bool isPrime(int val);
int countPrime(vector<int> &array);

int main() {
  int size;
  vector<int> array;
  cin >> size;
  for (int i = 0; i < size; i++) {
    int tmp;
    cin >> tmp;
    array.push_back(tmp);
  }
  cout << countPrime(array) << endl;
  return 0;
}

int countPrime(vector<int> &array) {
  int num = 0;
  for (int i = 0; i < array.size(); i++) {
    if (isPrime(array[i])) {
      num++;
    }
  }
  return num;
}

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

Error: TLE

Fixed submission:

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

bool isPrime(int val);
int countPrime(vector<int> &array);

int main() {
  int size;
  vector<int> array;
  cin >> size;
  for (int i = 0; i < size; i++) {
    int tmp;
    cin >> tmp;
    array.push_back(tmp);
  }
  cout << countPrime(array) << endl;
  return 0;
}

int countPrime(vector<int> &array) {
  int num = 0;
  for (int i = 0; i < array.size(); i++) {
    if (isPrime(array[i])) {
      num++;
    }
  }
  return num;
}

bool isPrime(int val) {
  if (val <= 1) {
    return false;
  }
  for (int i = 2; i <= val / 2; i++) {
    if (val % i == 0) {
      return false;
    }
  }
  return true;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  int a[10000];
  int i, j;

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

  int ans = 0;

  for (i = 0; i < n; i++) {
    j = 2;
    int m = sqrt(a[i]);
    while (a[i] % j != 0 && j <= m) {
      j++;
    }
    if (j > m)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  int a[10000];
  int i, j;

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

  int ans = 0;

  for (i = 0; i < n; i++) {
    j = 2;
    while (a[i] % j != 0) {
      j++;
    }
    if (a[i] == j)
      ans++;
  }

  cout << ans << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, pn, pnc = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> pn;
    if ((pn == 2) || (pn == 3))
      pnc += 1;
    else if (pn % 2 == 0) {
    } else {
      for (int j = 3; j <= pn / j; j += 2) {
        if (pn % j == 0) {
          pnc -= 1;
          break;
        }
      }
      pnc += 1;
    }
  }
  cout << pnc << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, pn, a, b, tmp, pnn, pnc = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> pn;
    pnn = 1;
    for (int j = 2; j < pn / 2 + 1; j++) {
      if ((pnn % 2) || (pnn % 3) || (pnn % 5) || (pnn % 7) || (pnn % 11) ||
          (pnn % 13)) {
        a = pn;
        b = j;
        while (b != 0) {
          tmp = b;
          b = a % b;
          a = tmp;
        }
        if (a == 1)
          pnn *= 1;
        else {
          pnn *= 0;
          break;
        }
      } else
        pnn *= 0;
    }
    if (pnn == 1)
      pnc += 1;
  }
  cout << pnc << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i, from, to) for (int i = from; i < to; ++i)
#define REP(i, from, to) for (int i = from; i <= to; ++i)
using namespace std;
template <typename T>
ostream &operator<<(ostream &out, const vector<vector<T>> &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}

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

void solve() {
  cin >> n;
  int ans = 0;
  rep(i, 0, n) {
    int k;
    cin >> k;
    if (isPrime(k)) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() { solve(); }

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i, from, to) for (int i = from; i < to; ++i)
#define REP(i, from, to) for (int i = from; i <= to; ++i)
using namespace std;
template <typename T>
ostream &operator<<(ostream &out, const vector<vector<T>> &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
const int maxn = 10010;
bool p[maxn];
int n;
void eratos() {
  p[0] = p[1] = true;
  rep(i, 0, maxn) {
    if (p[i]) {
      continue;
    }
    for (int j = i + i; j < maxn; j += i) {
      p[j] = true;
    }
  }
}
void solve() {
  eratos();
  cin >> n;
  int ans = 0;
  rep(i, 0, n) {
    int k;
    cin >> k;
    if (!p[k]) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() { solve(); }
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

// prime=>true, not prime=>false
// bool isPrime(int i){
//     for(int j=2; j<=i/2; j++){
//         if(i%j==0){
//             return false;
//         }
//     }
//     return true;
// }

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

int main() {

  int n;
  cin >> n;

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

  int prime_count = 0;
  for (int i = 0; i < n; i++) {
    if (isPrime(n_nums[i])) {
      prime_count += 1;
    }
  }

  cout << prime_count << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

// prime=>true, not prime=>false
bool primeJudge(int i) {
  for (int j = 2; j <= i / 2; j++) {
    if (i % j == 0) {
      return false;
    }
  }
  return true;
}

int main() {

  int n;
  cin >> n;

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

  int prime_count = 0;
  for (int i = 0; i < n; i++) {
    if (primeJudge(n_nums[i])) {
      prime_count += 1;
    }
  }

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

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

void Makepn(vector<int> &v, int n) {
  int count = 0;
  int i, j;
  vector<bool> pn(n + 1, true);
  pn[0] = false;
  pn[1] = false;
  for (i = 2; i < sqrt(n); i++) {
    if (pn[i]) {
      for (j = 0; i * (j + 2) < n; j++) {
        pn[i * (j + 2)] = false;
      }
    }
  }
  for (i = 2; i < n; i++) {
    if (pn[i]) {
      count++;
    }
  }
  v.resize(count);

  v[0] = 2;
  j = 1;
  for (i = 3; i <= n; i += 2) {
    if (pn[i]) {
      v[j++] = i;
    }
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  vector<int> pn;
  Makepn(pn, 10000);
  int n, num, ans;
  cin >> n;
  ans = n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    for (int j = 0; j < pn.size(); j++) {
      if (pn[j] * pn[j] > num)
        break;
      if (num % pn[j] == 0) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

void Makepn(vector<int> &v, int n) {
  int count = 1;
  int i, j;
  vector<bool> pn(n + 1, true);
  pn[0] = false;
  pn[1] = false;
  for (i = 2; i < sqrt(n); i++) {
    if (pn[i]) {
      for (j = 0; i * (j + 2) < n; j++) {
        pn[i * (j + 2)] = false;
      }
    }
  }
  for (i = 2; i < n; i++) {
    if (pn[i]) {
      count++;
    }
  }
  v.resize(count);

  v[0] = 2;
  j = 1;
  for (i = 3; i <= n; i += 2) {
    if (pn[i]) {
      v[j++] = i;
    }
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  vector<int> pn;
  Makepn(pn, 10000);
  int n, num, ans;
  cin >> n;
  ans = n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    for (int j = 0; j < pn.size(); j++) {
      if (pn[j] * pn[j] > num)
        break;
      if (num % pn[j] == 0) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n, i, j, ans = 0, end;
  long num;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    num < 10000 ? end = num : end = 10000;
    for (j = 2; j < end; j++)
      if (num % j == 0 && num != j) {
        num = 0;
        break;
      }
    num != 0 ? ans++ : 1;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, i, j, ans = 0;
  long num;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    for (j = 2; j < num; j++)
      if (num % j == 0 && num != j) {
        num = 0;
        break;
      }
    num != 0 ? ans++ : 1;
  }
  cout << ans << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool isPrime(int x) {
  if (x == 2) {
    return true;
  }
  if (x < 2 || x % 2 == 0) {
    return false;
  }
  int i = 3;
  while (i * i <= x) {
    if (x % i == 0) {
      return false;
    }
    i += 2;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  int count = 0;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (isPrime(a)) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool isPrime(int x) {
  if (x == 2) {
    return true;
  }
  if (x < 2 || x % 2 == 0) {
    return false;
  }
  int i = 3;
  while (i * i <= x) {
    if (x % i == 0) {
      return false;
      i += 2;
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  int count = 0;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (isPrime(a)) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n) {
  int i;
  if (n == 2)
    return true;
  else if (n < 2 || n % 2 == 0)
    return false;
  else {
    i = 3;
    while (i <= sqrt(n)) {
      if (n % i == 0)
        return false;
      i += 2;
    }
  }
  return true;
}

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n, x, i, j, k, l;
  cin >> n;
  l = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x == 2)
      l++;
    else if (x % 2 == 0) {
    } else {
      k = 0;
      for (j = 1; j <= x; j++) {
        if (x % j == 0)
          k++;
      }
      if (k == 2)
        l++;
    }
  }
  cout << l << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50001;

int prime[maxn], cnt, res;
bool isprime[maxn];

void maketable() {
  int base = (int)sqrt((double)maxn);
  isprime[0] = isprime[1] = 1;
  for (int i = 2; i < maxn; i++) {
    if (!isprime[i]) {
      prime[cnt++] = i;
      for (int j = i + i; j < maxn; j += i) {
        isprime[j] = 1;
      }
    }
  }
}

void solve(int n) {
  int k = (int)sqrt((double)n);
  for (int i = 0; prime[i] <= k; i++) {
    if (n % prime[i] == 0) {
      return;
    }
  }
  res++;
}

int main() {
  maketable();
  int n, s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s);
    solve(s);
  }
  printf("%d\\n", res);
  return 0;
}


Error: MLE

Fixed submission:


#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

const int maxn = 1e8 + 5;

int isprime[maxn];

void maketable() {
  isprime[0] = isprime[1] = 1;
  int n = ceil(sqrt(maxn));
  for (int i = 2; i <= n; i++) {
    if (!isprime[i]) {
      for (int j = i + i; j < maxn; j += i) {
        isprime[j] = 1;
      }
    }
  }
}

int main() {
  maketable();
  int s, n, cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s);
    if (!isprime[s]) {
      cnt++;
    }
  }
  printf("%d\\n", cnt);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

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

int main() {
  int n;
  scanf("%d", &n);

  int count = 0;
  for (int i = 0; i < n; i++) {
    int num;
    scanf("%d", &num);
    if (isPrime(num)) {
      count++;
    }
  }

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


Error: 0

Fixed submission:

#include <stdio.h>

#define N_MAX 10000

bool prime[N_MAX + 1];

int main() {
  for (int i = 0; i <= N_MAX; i++) {
    prime[i] = true;
  }
  prime[1] = false;
  for (int i = 2; i <= N_MAX; i++) {
    if (prime[i] == false)
      continue;

    for (int j = 2; j <= N_MAX; j++) {
      if (i * j > N_MAX)
        break;
      prime[i * j] = false;
    }
  }

  int n;
  scanf("%d", &n);

  int count = 0;
  for (int i = 0; i < n; i++) {
    int num;
    scanf("%d", &num);
    if (prime[num])
      count++;
  }

  printf("%d\\n", count);
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error


#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void) {
  int n, a, b, count, c, w;
  double d;
  n = 0;
  b = 0;
  cin >> n;
  // cout<<"n="<<n<<endl;
  count = 0;
  for (a = 0; a < n; a++) {
    cin >> b;
    d = b;
    // cout<<b<<" ";
    for (w = 0; w <= 0; w++) {
      if (b == 2) {
        break;
      }
      if (b % 2 == 0 || b == 1) {
        // cout<<"NO"<<endl;
        count++;
        break;
      }
      for (c = 3; sqrt(d) >= c; c = c + 2) {
        if (b % c == 0) {
          count++;
          // cout<<"NO"<<endl;
          break;
        }
      }
    }
  }
  cout << n - count << endl;
  return 0;
}


Error: -11

Fixed submission:


#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void) {
  int x[100000000], y, d, a, b, n;
  double c;
  cin >> n;
  for (a = 0; a < n; a++) {
    cin >> c;
    if (c == 2) {
    } else if (x[a] % 2 == 0) {
      y++;
    } else if (c == 1) {
      y++;
    } else {
      for (b = 3; sqrt(c) >= b; b = b + 2) {
        if (x[a] % b == 0) {
          y++;
          break;
        }
      }
    }
  }
  d = n - y;
  cout << d << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MAX 10000001

static bool gosei[MAX];

void a() {
  for (int i = 2; i <= sqrt(MAX); i++)
    if (gosei[i] == false) {
      for (int j = 2, k = 0; (k = i * j) <= MAX; j++)
        gosei[k] = true;
    }
}

int c(int a) {
  if (a % 2 == 0)
    return 0;
  for (int i = 3; i <= sqrt(a); i += 2)
    if (a % i == 0)
      return 0;
  return 1;
}

int main() {
  a();
  int b = 0;
  for (int a; cin >> a;) {
    if (a < MAX) {
      if (!gosei[a])
        b++;
    } else
      b += c(a);
  }
  cout << b << endl;
  return 0;
}

Error: WA

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MAX 10000001

static bool gosei[MAX];

void a() {
  for (int i = 2; i <= sqrt(MAX); i++)
    if (gosei[i] == false) {
      for (int j = 2, k = 0; (k = i * j) <= MAX; j++)
        gosei[k] = true;
    }
}

int main() {
  a();
  int b = 0;
  for (int a; cin >> a;)
    if (!gosei[a])
      b++;
  cout << b << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
int main() {
  using namespace std;
  int len;
  cin >> len;
  int *prime = new int[len];
  int *num = new int[len];
  int count = 0;
  for (int i = 0; i < len; i++) {
    cin >> num[i];
    int isprime = 1;
    for (int j = 0; j < count; j++) {
      if (num[i] % prime[j] == 0 && num[i] != prime[j]) {
        isprime = 0;
        break;
      }
    }
    if (!isprime)
      continue;
    for (int j = 2; j <= sqrt(num[i]); j++) {
      if (num[i] % j == 0 && num[i] != j) {
        isprime = 0;
        break;
      }
    }
    if (isprime)
      prime[count++] = num[i];
  }
  cout << count << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
int main() {
  using namespace std;
  int len;
  cin >> len;
  int *prime = new int[len];
  int *num = new int[len];
  int count = 0;
  for (int i = 0; i < len; i++) {
    cin >> num[i];
    int isprime = 1;
    for (int j = 0; j < count; j++) {
      if (num[i] % prime[j] == 0 && num[i] != prime[j]) {
        isprime = 0;
        break;
      }
    }
    if (!isprime)
      continue;
    for (int j = 2; j < num[i]; j++) {
      if (num[i] % j == 0 && num[i] != j) {
        isprime = 0;
        break;
      }
    }
    if (isprime)
      prime[count++] = num[i];
  }
  cout << count << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

template <typename T> T Input() {
  T value;
  std::cin >> value;
  return value;
}

int main() {
  std::vector<bool> isPrime(100000001);
  for (auto i = 0; i < 100000000; ++i)
    isPrime[i] = false;

  for (auto i = 3; i <= 100000000; i += 2)
    isPrime[i] = true;

  isPrime[2] = true;

  for (auto i = 3; i * i <= 100000000; i += 2)
    if (isPrime[i] == true)
      for (auto j = i * i; j <= 100000000; j += i)
        isPrime[j] = false;

  int num, count = 0;
  std::vector<int> arr;

  std::cin >> num;

  for (auto i = 0; i < num; ++i)
    arr.push_back(Input<int>());

  for (auto elem : arr)
    if (isPrime[elem])
      ++count;

  std::cout << count << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

template <typename T> T Input() {
  T value;
  std::cin >> value;
  return value;
}

int main() {
  bool isPrime[100001];
  for (auto i = 0; i < 100000; ++i)
    isPrime[i] = false;

  for (auto i = 3; i <= 100000; i += 2)
    isPrime[i] = true;

  isPrime[2] = true;

  for (auto i = 3; i * i <= 100000; i += 2)
    if (isPrime[i] == true)
      for (auto j = i * i; j <= 100000; j += i)
        isPrime[j] = false;

  int num, count = 0;
  std::vector<int> arr;

  std::cin >> num;

  for (auto i = 0; i < num; ++i)
    arr.push_back(Input<int>());

  for (auto elem : arr)
    if (isPrime[elem])
      ++count;

  std::cout << count << "\\n";

  return 0;
}