alexjercan/bugnet huggingface dataset:
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 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 / 2; 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;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

bool is_prime(int64_t n) {
  if (n == 2) {
    return true;
  } else if (n % 2 == 0) {
    return false;
  }

  for (int64_t i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int32_t N, count = 0;

  cin >> N;

  for (int32_t i = 0; i < N; i++) {
    int64_t n;
    cin >> n;

    if (is_prime(n)) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

bool is_prime(int64_t n) {
  if (n == 2) {
    return true;
  } else if (n % 2 == 0) {
    return false;
  }

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

  return true;
}

int main() {
  int32_t N, count = 0;

  cin >> N;

  for (int32_t i = 0; i < N; i++) {
    int64_t n;
    cin >> n;

    if (is_prime(n)) {
      count++;
    }
  }

  cout << count << endl;

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, value, i, j, flag, cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> value;
    flag = 1;
    if (value == 2)
      cnt++;
    if (value == 1 || value % 2 == 0)
      continue;
    for (j = 3; j * j <= value; j += 2) {
      if (value % j == 0) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      cnt++;
      // cout<<value<<endl;
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, value, i, j, flag, cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> value;
    flag = 1;
    if (value == 2)
      cnt++;
    if (value % 2 == 0)
      continue;
    for (j = 3; j < value; j += 2) {
      if (value % j == 0) {
        flag = 0;
        break;
      }
    }
    if (flag == 1)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

bool is_prime(unsigned i) {
  if (i == 2)
    return true;
  if (i == 1 || !(i % 2))
    return false;
  for (unsigned j = 3; j <= sqrt(i); j += 2) {
    if (!(i % j))
      return false;
  }
  return true;
}

int main() {
  int n, t, c = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (is_prime(t))
      c++;
  }
  cout << c << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

class primes_list {
public:
  primes_list(void) { primes_list(0); }
  primes_list(size_t i) {
    primes.push_back(false); // is_prime(1)=false
    primes.push_back(true);  // is_prime(2)=false
    gen(i);
  }
  bool is_prime(size_t i) {
    if (primes.size() < i)
      gen(i);
    return primes[i - 1];
  }
  void gen(size_t i) {
    if (primes.size() >= i)
      return;
    try {
      primes.resize(i, true);
    } catch (std::exception e) {
      cout << "error on memory allocation" << endl;
      throw(e);
    }
    for (size_t j = 2; j < i; j++) {
      if (primes[j - 1]) {
        for (int k = j + j; k <= primes.size(); k += j) {
          primes[k - 1] = false;
        }
      }
    }
  }

private:
  std::vector<bool> primes;
};

int main() {
  primes_list p(1000000);
  int n, t, c = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (p.is_prime(t))
      c++;
  }
  cout << c << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int x, n, i;
float isprime() {
  int j = 3;
  if (x == 2)
    return true;
  else if (x < 2 || x % 2 == 0)
    return false;
  else {
    while (j <= sqrt(x)) {
      if (x % j == 0) {
        return false;
      }
      j = j + 2;
    }
    return true;
  }
}
int main() {
  int count = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    isprime();
    if (isprime() == true)
      count++;
  }
  cout << count << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, a, count = 0, flag = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 2) {
      count++;
    } else {
      for (int j = 2; j < a; j++) {
        if (a % j == 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        count++;
      }
    }
    flag = 0;
  }
  cout << count << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N, A[10000];

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

int main(void) {
  cin >> N;

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

Error: TLE

Fixed submission:

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

int N, A[10000];

bool isPrimeNumber(int x) {
  if (x != 2 && x % 2 == 0)
    return false;
  for (int i = 2; i < x; i++) {
    if (x % i == 0)
      return false;
  }
  return true;
}

int main(void) {
  cin >> N;

  int cnt = 0, x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (isPrimeNumber(x))
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
void nhapkt(int &n) { cin >> n; }
void NhapMT(int a[], int n) {
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
}
bool isSNT(int k) {
  if (k == 2)
    return true;
  if (k < 2 || k % 2 == 0)
    return false;
  for (int i = 3; i * i <= k; i = i + 2) {
    if (k % i == 0)
      return false;
  }
  return true;
}
void CountPN(int a[], int n) {
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (isSNT(a[i]))
      d++;
  }
  cout << d << endl;
}
int main() {
  int n;
  int a[10000];
  nhapkt(n);
  NhapMT(a, n);
  CountPN(a, n);
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
void nhapkt(int &n) { cin >> n; }
void NhapMT(int a[], int n) {
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
}
bool isSNT(int k) {
  int d = 0;
  for (int i = 1; i <= k; i++) {
    if (k % i == 0) {
      d++;
    }
  }
  if (d != 2)
    return false;
  return true;
}
void CountPN(int a[], int n) {
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (isSNT(a[i]))
      d++;
  }
  cout << d << endl;
}
int main() {
  int n;
  int a[10000];
  nhapkt(n);
  NhapMT(a, n);
  CountPN(a, n);
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int>>

template <class X> void print(X Target) { cout << Target << '\\n'; }

bool isprime(int num) {
  if (num == 2) {
    return (true);
  } else if (num == 1 || num % 2 == 0) {
    return (false);
  }
  for (int i = 3; i <= num / i; i += 2) {
    if (num % i == 0) {
      return (false);
    }
  }

  return (true);
}

signed main() {
  ios::sync_with_stdio(false);

  int n, cnt = 0;
  cin >> n;
  while (n--) {
    int num;
    cin >> num;
    if (isprime(num)) {
      cnt++;
    }
  }
  print(cnt);

  return (0);
}

Error: MLE

Fixed submission:

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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int>>

template <class X> void print(X Target) { cout << Target << '\\n'; }

const int MAX = 100000000;

signed main() {
  ios::sync_with_stdio(false);
  static int prime[MAX + 1] = {true, true};

  for (int i = 2; i <= MAX; i++) {
    if (!prime[i]) {
      for (int j = i * i; j <= MAX; j += i) {
        prime[j] = true;
      }
    }
  }

  int n, cnt = 0;
  cin >> n;
  while (n--) {
    int num;
    cin >> num;
    if (!prime[num]) {
      cnt++;
    }
  }
  print(cnt);

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


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

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

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

Error: MLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;

int memo[100000001];
int dp[100000001];

int main() {
  int N;
  cin >> N;

  memo[0] = true;
  memo[1] = true;

  int im = sqrt(100000000) + 1;
  for (int i = 2; i <= im; i += 2) {
    if (!memo[i]) {
      for (int j = i * i; j <= 100000000; j += i) {
        memo[j] = true;
      }
    }
  }
  for (int i = 2; i <= im; i++) {
    if (!memo[i])
      dp[i] = dp[i - 1] + 1;
    else
      dp[i] = dp[i - 1];
  }

#ifdef DEBUG
  for (int i = 1; i <= 100; i++) {
    cout << memo[i] << " ";
  }
  cout << endl;
#endif

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans = max(ans, dp[x]);
  }
  cout << ans << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int d[n], max = -1;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    max = max < d[i] ? d[i] : max;
  }

  vector<int> pr;
  pr.push_back(2);
  for (int i = 3; i <= sqrt(max); i++) {
    for (int j = 0; j < pr.size() && pr[j] <= sqrt(i); j++) {
      if (i % pr[j] == 0)
        goto BREAK;
    }
    pr.push_back(i);
  BREAK:;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < pr.size() && pr[j] <= sqrt(d[i]); j++) {
      if (d[i] % pr[j] == 0)
        goto BREAK2;
    }
    cnt++;
  BREAK2:;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:


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

int main() {
  int n, cnt = 0;
  cin >> n;
  while (n--) {
  A:
    int c;
    cin >> c;
    double Sq = sqrt(c);
    for (int i = 2; i <= Sq; i++) {
      if (c % i == 0) {
        n--;
        goto A;
      }
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  int cnt = 0;

  vector<int> a(n);

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

    bool flag = true;

    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        flag = 0;
        break;
      }
    }

    if (flag)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  int cnt = 0;

  vector<int> a(n);

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

    int flag = 1;

    for (int j = 2; j < a[i]; j++) {
      if (a[i] % j == 0) {
        flag = 0;
        break;
      }
    }

    if (flag)
      cnt++;
  }

  cout << cnt << endl;

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

#include <cmath>
#include <cstdio>
int main(void) {

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

  int c = 0;

  for (i = 0; i < n; i++) {

    int y = sqrt(a[i]);
    //	printf("y=%d\\n",y);
    int j;

    if (y == 1) {
      c++;
    } else {
      for (j = 2; j <= y; j++) {
        // if(a[i]%j==0) {printf("i=%d\\nj=%d\\n",i,j);}
        if (a[i] % j == 0)
          break;
      }
      // printf("%d\\n",j);
      if (j == y + 1) {
        c++;
      }
    }
  }
  printf("%d\\n", c);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main(void) {

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

  int c = 0;

  for (i = 0; i < n; i++) {
    int x = 0, y = a[i];
    while (y - x > 1) {
      int z = (x + y) / 2;
      if (z * z >= a[i]) {
        x = z;
      } else {
        y = z;
      }
    }

    int j;
    for (j = 2; j <= y; j++) {
      if (a[i] % j == 0)
        break;
    }
    if (j + 1 > y) {
      c++;
    }
  }

  printf("%d\\n", c);

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

#include <cmath>
#include <iostream>

int isprime(int);
using namespace std;

int main() {
  int i, j, n, b = 0;

  cin >> n;

  int a[n];

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

  for (i = 0; i < n; i++) {
    if (isprime(a[i]) == true)
      b++;
  }

  cout << b << endl;

  return 0;
}

int isprime(int x) {
  int j;

  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

  j = 3;

  while (j <= sqrt(x)) {
    if (x % j == 0) {
      return false;
    }

    j = j + 2;
  }

  return true;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int i, j, n, b = 0;

  cin >> n;

  int a[n];

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

  for (i = 0; i < n; i++) {

    if (a[i] == 2) {
      b++;
      continue;
    }

    else if (a[i] < 2 || a[i] % 2 == 0)
      continue;

    j = 3;

    while (j <= sqrt(a[i]))
      if (a[i] % i == 0)
        break;

    j = j + 2;
    b++;
  }

  cout << b << endl;

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

#include <math.h>
#include <stdbool.h>
#include <stdio.h>

bool isPrime(int num) {
  if (num < 2)
    return false;
  if (num == 2)
    return true;
  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 a[100000] = {};
  int n;
  int count = 0;

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

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

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int a[100000] = {};
  int b[100000] = {};
  int k = 0;
  int n;
  int count = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= a[i]; j++)
      if (a[i] % j == 0)
        count++;
    if (count == 2) {
      b[k] = a[i];
      k++;
    }
    count = 0;
  }

  printf("%d\\n", k);
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

const int INF = 1000000007;

bool isprime[10000];
int prime[10000];
int lim = 0;

void eratosthenes() {
  for (int i = 0; i < 10000; i++) {
    isprime[i] = true;
  }
  isprime[0] = isprime[1] = false;
  for (int x = 2; x < 10000; x++) {
    if (isprime[x]) {
      prime[lim++] = x;
      for (int y = x * x; y < 10000; y += x) {
        isprime[y] = false;
      }
    }
  }
}

int main() {
  eratosthenes();
  int N, a, ans;
  ans = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a);
    bool flg = true;
    for (int i = 0; i < lim; i++) {
      if (prime[i] >= a)
        break;
      if (a % prime[i] == 0) {
        flg = false;
        break;
      }
    }
    if (flg)
      ++ans;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

const int LIM = 100000000;
bool notprime[LIM];

void take_prime() {
  notprime[0] = notprime[1] = true;
  int m = 2;
  while (m < 10000) {
    if (!notprime[m]) {
      int j = m * m;
      while (j < LIM) {
        notprime[j] = true;
        j += m;
      }
    }
    m++;
  }
}

int main() {
  take_prime();
  short N, cnt = 0;
  cin >> N;
  while (N-- > 0) {
    short a;
    cin >> a;
    if (!notprime[a]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

constexpr int INF = 1000000000; /* 1e+9a */
constexpr int MODULO = 1000000007;

constexpr int evx[4] = {1, 0, -1, 0};
constexpr int evy[4] = {0, 1, 0, -1};

//----------------------------------
//----------------------------------

constexpr int Sup = 5000;
bool number[Sup];
vector<int> primes;

void era() {
  for (int i = 0; i < Sup; ++i) {
    number[i] = true;
  }

  primes.push_back(2);
  primes.push_back(3);
  int prime = 1; // 2n + 1 -> n
  while (true) {
    int add = 2 * prime + 1;
    for (int i = prime + add; i < Sup; i += add) {
      number[i] = false;
    }
    int j = prime + 1;
    while (true) {
      if (j >= Sup)
        return;
      else if (number[j]) {
        prime = j;
        primes.push_back(2 * prime + 1);
        break;
      }
      j++;
    }
  }
}

inline bool test_divid(int n) {
  if (n < 10000)
    return binary_search(primes.begin(), primes.end(), n);
  else
    for (auto p : primes) {
      if (n % p == 0)
        return false;
    }
  return true;
}

signed main() {
  ios::sync_with_stdio(false);
  era();
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    ans += test_divid(tmp);
  }
  cout << ans << '\\n';
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

constexpr int INF = 1000000000; /* 1e+9a */
constexpr int MODULO = 1000000007;

constexpr int evx[4] = {1, 0, -1, 0};
constexpr int evy[4] = {0, 1, 0, -1};

//----------------------------------
//----------------------------------

constexpr int Sup = 50000000;
bool number[Sup];
vector<int> primes;

void era() {
  for (int i = 0; i < Sup; ++i) {
    number[i] = true;
  }

  primes.push_back(2);
  primes.push_back(3);
  int prime = 1; // 2n + 1 -> n
  while (true) {
    int add = 2 * prime + 1;
    for (int i = prime + add; i < Sup; i += add) {
      number[i] = false;
    }
    int j = prime + 1;
    while (true) {
      if (j >= Sup)
        return;
      else if (number[j]) {
        prime = j;
        primes.push_back(2 * prime + 1);
        break;
      }
      j++;
    }
  }
}

signed main() {
  ios::sync_with_stdio(false);
  era();
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    ans += binary_search(primes.begin(), primes.end(), tmp);
  }
  cout << ans << '\\n';
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

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

int main() {
  int n = 0;
  fscanf(stdin, "%d", &n);
  int cnt = 0;
  map<int, int> memo;
  for (int i = 0; i < n; ++i) {
    int m = 0;
    fscanf(stdin, "%d", &m);
    if (memo.count(m)) {
      cnt += memo[m];
    } else if (is_prime(m)) {
      ++cnt;
      memo[m] = 1;
    } else {
      memo[m] = 0;
    }
  }
  fprintf(stdout, "%d\\n", cnt);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

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

int main() {
  int n = 0;
  fscanf(stdin, "%d", &n);
  int cnt = 0;
  vector<int> memo(10005, -1);
  for (int i = 0; i < n; ++i) {
    int m = 0;
    fscanf(stdin, "%d", &m);
    if (memo[m] != -1) {
      cnt += memo[m];
    } else if (is_prime(m)) {
      ++cnt;
      memo[m] = 1;
    } else {
      memo[m] = 0;
    }
  }
  fprintf(stdout, "%d\\n", cnt);
  return 0;
}