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

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n, i, x, j, flag = 0, cut = 0, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a = sqrt(x);
    flag = 0;
    for (j = a; j > 1; j--) {
      if (x % j == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      cut++;
  }
  cout << cut << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n, i, x, j, flag = 0, cut = 0, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a = sqrt(x);
    flag = 0;
    for (j = x - 1; j > 1; j--) {
      if (x % j == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      cut++;
  }
  cout << cut << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main() {

  int n;
  cin >> n;

  int *in = new int[n];

  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    if (IsPrime(in[i]))
      count++;
  }

  cout << count << endl;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  int n;
  cin >> n;

  int *in = new int[n];

  int maxi = -1;
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    if (maxi == -1 || maxi < in[i])
      maxi = in[i];
  }

  maxi = maxi + 1;
  bool *x = new bool[maxi];
  for (int i = 0; i < maxi; i++) {
    x[i] = true;
  }

  x[0] = false;
  x[1] = false;
  for (int i = 2; i < maxi; i++) {
    if (x[i]) {
      for (int j = 2; i * j <= maxi; j++) {
        x[i * j] = false;
      }
    }
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (x[in[i]])
      count++;
  }
  cout << count << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

// IN THE NAME OF GOD

#include <iostream>
using namespace std;
typedef long long int ll;
int a, n, ans, d;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    for (int j = 2; j * j <= a; j++) {
      if (!(a % j)) {
        a = -1;
        break;
      }
    }
    if (a != -1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: MLE

Fixed submission:

// IN THE NAME OF GOD

#include <iostream>
using namespace std;
typedef long long int ll;
bool b[100000009];
int a, n, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i <= 10000; i++) {
    if (!b[i]) {
      for (int j = i * i; j <= 100000000; j += i)
        b[j] = 1;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!b[a]) {
      ans++;
      b[a] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

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

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

Error: MLE

Fixed submission:

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

bool prime[100000000];

void build_table();

void check();

int main() {
  build_table();
  // check();

  int n;
  cin >> n;
  int cnt = 0;
  int in;
  for (int i = 0; i < n; i++) {
    cin >> in;
    if (prime[in] == true)
      cnt++;
  }
  cout << cnt << endl;
}

void build_table() {

  for (int i = 0; i < 100000000; i++)
    prime[i] = true;

  int sqrt_num = sqrt(100000000);
  prime[0] = prime[1] = false;
  for (int i = 2; i <= sqrt_num; i++) {
    if (prime[i]) {
      for (int k = (100000000 - 1) / i, j = k * i; k >= i; k--, j -= i) {
        if (prime[k])
          prime[j] = false;
      }
    }
  }
}

void check() {
  for (int i = 0; i < 100; i++)
    if (prime[i])
      cout << i << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
bool heheda(int a);

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

int main() {
  int n;
  cin >> n;
  int tmp2 = 0;
  int c;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (heheda(c))
      tmp2 += 1;
  }
  cout << tmp2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool heheda(int a);

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

int main() {
  int n;
  cin >> n;
  int tmp2 = 0;
  int c;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (heheda(c))
      tmp2 += 1;
  }
  cout << tmp2 << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  ;
  cin >> m;
  int count = m;
  for (int s = 0; s < m; s++) {
    cin >> n;
    if (n == 2)
      continue;
    else if (n % 2 == 0)
      count--;
    else {
      for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
          count--;
          break;
        }
      }
    }
  }
  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  ;
  cin >> m;
  int count = m;
  for (int s = 0; s < m; s++) {
    cin >> n;
    if (n == 2)
      continue;
    else if (n % 2 == 0)
      count--;
    else {
      for (int i = 3; i < n; i += 2) {
        if (n % i == 0) {
          count--;
          break;
        }
      }
    }
  }
  cout << count << endl;

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

#include <iostream>
#include <set>
#include <vector>

using namespace std;

vector<bool> prime(int d) {
  vector<bool> arr(d + 1, true);
  arr[0] = arr[1] = false;

  for (int i = 2; i * i <= d; i++) {
    if (!arr[i])
      continue;
    for (int j = 2; j * i <= d; j++) {
      if (!arr[j * i])
        continue;
      arr[j * i] = false;
    }
  }

  return arr;
}

int main(int argc, char *argv[]) {
  int N;
  cin >> N;

  int m = 0;
  vector<int> input;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    input.push_back(d);
    m = max(m, d);
  }

  vector<bool> arr = prime(m);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (arr[input[i]])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>

using namespace std;

vector<unsigned long> prime(int d) {
  int n = d / 32 + 1;
  vector<unsigned long> arr(n, -1);

  for (int i = 2; i <= d; i++) {
    int indx = i / 32;
    int offset = (i % 32) - 1;
    if (((arr[indx] >> offset) & 1) == 0)
      continue;

    for (int j = 2; j * i <= d; j++) {
      int indx = j * i / 32;
      int offset = (j * i % 32) - 1;
      if (((arr[indx] >> offset) & 1) == 0)
        continue;
      arr[indx] ^= (1 << offset);
    }
  }
  return arr;
}

int main(int argc, char *argv[]) {
  int N;
  cin >> N;

  int m = 0;
  vector<int> in;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    in.push_back(d);
    m = max(m, d);
  }

  vector<unsigned long> arr = prime(m);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int indx = in[i] / 32;
    int offset = (in[i] % 32) - 1;
    if (((arr[indx] >> offset) & 1) == 0)
      continue;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

bool isPrime(int a) {
  int squared = sqrt(a);
  for (int i = 2; i <= squared; ++i) { // only need to test up to squareroot
    if (a % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {

  int n; // number of inputs

  cin >> n;

  int prime_count = 0;

  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;
    if (isPrime(input))
      ++prime_count;
  }

  cout << prime_count << endl;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>
#define N 100000000

using namespace std;

bool sieve[N + 1];

int main() {

  // initialize sieve of Eratosthenes
  for (int i = 2; i <= N; ++i) { // from smallest prime 2
    sieve[i] = true;             // set all to true
  }

  for (int i = 2; i <= N; i++) {
    if (sieve[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        sieve[j] = false; // sieve multiples of primes
      }
    }
  }

  int n; // number of inputs

  cin >> n;

  int prime_count = 0;

  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;
    if (sieve[input] == true)
      ++prime_count;
  }

  cout << prime_count << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  int in;
  int half_in;
  int num_prime = 0;
  bool isPrime = true;

  scanf("%d", &n);
  if (n < 1 || n > 10000) {
    printf("Error: n is out of range");
    return -1;
  }

  for (int i = 0; i < n; i++) {
    scanf("%d", &in);
    if (in < 2 || in > 10e8) {
      printf("Error: the input is out of range");
      return -1;
    }

    // check if is prime
    if (in == 2 || in == 3) {
      isPrime = true;
    } else if (in % 2 == 0) {
      isPrime = false;
    } else if (in % 2 != 0) {
      for (int i = 3; i <= sqrt(in); i += 2) {
        if (in % i == 0) {
          isPrime = false;
          break;
        }
      }
    }

    if (isPrime == false) {
      isPrime = true;
      continue;
    } else if (isPrime == true) {
      num_prime += 1;
      /* printf("is prime\\n"); */
    }
  }

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  int in;
  int num_prime = 0;
  bool isPrime = true;

  scanf("%d", &n);
  if (n < 1 || n > 10000) {
    printf("Error: n is out of range");
    return -1;
  }

  for (int i = 0; i < n; i++) {
    scanf("%d", &in);
    if (in < 2 || in > 10e8) {
      printf("Error: the input is out of range");
      return -1;
    }

    // check if is prime
    if (in == 2 || in == 3) {
      isPrime = true;
    } else if (in % 2 == 0) {
      isPrime = false;
    } else if (in % 2 != 0) {
      for (int i = 3; i < in - 1; i += 2) {
        if (in % i == 0) {
          isPrime = false;
          break;
        }
      }
    }

    if (isPrime == false) {
      isPrime = true;
      continue;
    } else if (isPrime == true) {
      num_prime += 1;
      /* printf("is prime\\n"); */
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES

using namespace std;

bool isPrime(int n) {

  int i = 3;

  if (n == 2)
    return true;
  if (n <= 1 || n % 2 == 0)
    return false;

  while (i <= sqrt(n)) {
    if (n % i == 0)
      return false;
    i = i + 2;
  }
  return true;
}

int main() {

  int n, cnt = 0, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (isPrime(x))
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES

using namespace std;

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

int main() {

  int n, cnt = 0, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (isPrime(x))
      cnt++;
  }

  cout << cnt << endl;

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

#include <cstdio>
#include <cstring>

typedef long long int lli;

char prime[50000002];

int main(void) {
  //    memset(prime, 0xFF, sizeof(prime));
  prime[0] = 1;
  for (lli i = 3; i < 100000002; i += 2)
    if (!prime[i / 2])
      for (lli j = 3; i * j < 100000002; j += 2)
        prime[i * j / 2] = 1;

  int n;
  scanf("%d", &n);
  int res = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (!(a % 2) && a - 2)
      continue;
    if (!prime[a / 2])
      res++;
  }
  printf("%d\\n", res);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

typedef long long int lli;

char prime[50000012];

int main(void) {
  //    memset(prime, 0xFF, sizeof(prime));
  prime[0] = 1;
  for (lli i = 3; i < 100000020; i += 2)
    if (!prime[i / 2])
      for (lli j = 3; i * j < 100000020; j += 2)
        prime[i * j / 2] = 1;

  int n;
  scanf("%d", &n);
  int res = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (!(a % 2) && a - 2)
      continue;
    if (!prime[a / 2])
      res++;
  }
  printf("%d\\n", res);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

bool notPrime[50000005] = {};

void calcPrimes(int n) {
  int sqrtn = static_cast<int>(sqrt(n));
  notPrime[0] = true;
  for (int i = 3; i <= sqrtn; i += 2) {
    if (notPrime[i / 2])
      continue;
    for (int j = i * i; j <= n; j += 2 * i)
      notPrime[j / 2] = true;
  }
}

int main() {
  int N = 0;
  cin >> N;
  vector<int> nums(N);
  for (auto &num : nums)
    cin >> num;
  int numMax = 0;
  numMax = *max_element(nums.begin(), nums.end());
  calcPrimes(numMax);
  int counter = 0;
  for (auto &num : nums) {
    if (num == 2 || ((num & 1) && !notPrime[num / 2]))
      ++counter;
  }
  cout << counter << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

bool notPrime[100000005] = {};

void calcPrimes(int n) {
  int sqrtn = static_cast<int>(sqrt(n));
  notPrime[1] = true;
  for (int i = 2; i <= sqrtn; ++i) {
    if (notPrime[i])
      continue;
    for (int j = i * i; j <= n; j += i)
      notPrime[j] = true;
  }
}

int main() {
  int N = 0;
  cin >> N;
  vector<int> nums(N);
  for (auto &num : nums)
    cin >> num;
  int numMax = 0;
  numMax = *max_element(nums.begin(), nums.end());
  calcPrimes(numMax);
  int counter = 0;
  for (auto &num : nums) {
    if (!notPrime[num])
      ++counter;
  }
  cout << counter << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

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

// void get(vector<int> &prime1, int max){
//	bool prime2[max+1];
//	prime2[1] = prime2[0] = false;
//	for(int a = 2; a<=max; a++){
//		prime2[a] = true;
//	}
//	if(max>=4){
//		for(int i=2; i<=sqrt((double)max); i++){
//			if(prime2[i]) {
//			for(int j=i; i*j<=max ;j++)
//			{
//				for(int k = j*i; k<=max; k*=i)
//				prime2[k] = false;
//			}
//
//			}
//		}
//	}
//	for(int x = 0; x<=max; x++){
//		if(prime2[x])
//		prime1.push_back(x);
//	}
// }

bool IsPrime(int max) {
  for (int i = 2; i <= sqrt((double)max); i++) {
    if (max % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int count = 0;
  int max = 0;
  int array[n];
  vector<int> prime1;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
    //		if(array[i]>max)
    //		max = array[i];
    if (IsPrime(array[i]))
      count++;
  }

  //	get(prime1, max);

  //	for(int i = 0; i<n; i++){
  //		for(int j = 0; j<prime1.size(); j++){
  //			if(array[i] == prime1[j])
  //			count++;
  //		}
  //	}
  cout << count << endl;
  return 0;
}

Error: 0

Fixed submission:

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

// void get(vector<int> &prime1, int max){
//	bool prime2[max+1];
//	prime2[1] = prime2[0] = false;
//	for(int a = 2; a<=max; a++){
//		prime2[a] = true;
//	}
//	if(max>=4){
//		for(int i=2; i<=sqrt((double)max); i++){
//			if(prime2[i]) {
//			for(int j=i; i*j<=max ;j++)
//			{
//				for(int k = j*i; k<=max; k*=i)
//				prime2[k] = false;
//			}
//
//			}
//		}
//	}
//	for(int x = 0; x<=max; x++){
//		if(prime2[x])
//		prime1.push_back(x);
//	}
// }

bool IsPrime(int max) {
  bool prime2[max + 1];
  prime2[1] = prime2[0] = false;
  for (int a = 2; a <= max; a++) {
    prime2[a] = true;
  }
  if (max >= 4) {
    for (int i = 2; i <= sqrt((double)max); i++) {
      if (prime2[i]) {
        for (int j = i; i * j <= max; j++) {
          for (int k = j * i; k <= max; k *= i)
            prime2[k] = false;
        }
      }
    }
  }
  return prime2[max];
}

int main() {
  int n;
  cin >> n;
  int count = 0;
  int max = 0;
  int array[n];
  vector<int> prime1;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
    //		if(array[i]>max)
    //		max = array[i];
    if (IsPrime(array[i]))
      count++;
  }

  //	get(prime1, max);

  //	for(int i = 0; i<n; i++){
  //		for(int j = 0; j<prime1.size(); j++){
  //			if(array[i] == prime1[j])
  //			count++;
  //		}
  //	}
  cout << count << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int squrtInt(int x) {
  if (x < 4) {
    return 1;
  } else {
    int i = 2;
    while (i < x) {
      if (i * i > x) {
        return i - 1;
      }
      i++;
    }
  }
  return 1;
}
bool isPrime(int x) {
  if (x == 1 || (x > 2 && x % 2 == 0)) {
    return false;
  }
  int i = 3, max = squrtInt(x) + 1;
  // cout << x << ", " << max << endl;
  while (i < max) {
    if (x % i == 0) {
      return false;
    }
    i += 2;
  }
  return true;
}
int main() {
  int n, i, x, cnt = 0;
  vector<int> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  vector<int>::iterator ite = v.begin();
  while (ite != v.end()) {
    if (isPrime(*ite)) {
      /*if(cnt++ != 0){
          cout << " ";
      }
      cout << *ite;
      */
      cnt++;
    }
    ite++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

bool isPrime(int x) {
  if (x == 1 || (x > 2 && x % 2 == 0)) {
    return false;
  }
  int i = 3;
  while (i < x) {
    if (x % i == 0) {
      return false;
    }
    i += 2;
  }
  return true;
}
int main() {
  int n, i, x, cnt = 0;
  vector<int> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  vector<int>::iterator ite = v.begin();
  while (ite != v.end()) {
    if (isPrime(*ite)) {
      /*if(cnt++ != 0){
          cout << " ";
      }
      cout << *ite;
      */
      cnt++;
    }
    ite++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int main() {
  int n, a;
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (judge(a)) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int s[100000] = {};

bool judge(int n) {
  bool j = true;
  for (int i = 0; s[i] * s[i] <= n; i++) {
    if (s[i] == 0) {
      return j;
    }
    if (n % s[i] == 0) {
      return j = false;
    }
  }
  return j;
}

int main() {

  s[0] = 2;
  int c = 1;
  for (int i = 3; i < 100000; i += 2) {
    if (judge(i)) {
      s[c] = i;
      c++;
    }
  }

  int count = 0;
  int n, a[5000] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (judge(a[i])) {
      count++;
    }
  }

  cout << count << endl;

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

#include <iostream>

using namespace std;

int main() {
  int a, d = 0;
  cin >> a;
  for (int i = 0; i < a; i++) {
    int b;
    cin >> b;
    d++;
    for (int j = 2; j * j <= b; j++) {
      if (b % j == 0) {
        d--;
        break;
      }
    }
  }
  cout << d << endl;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, d = 0;
  cin >> a;
  for (int i = 0; i < a; i++) {
    int b;
    cin >> b;
    d++;
    for (int j = 2; j < b / 2 + 1; j++) {
      if (b % j == 0) {
        d--;
        break;
      }
    }
  }
  cout << d << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int time, atai, ansa = 0;
  cin >> time;
  long suuti;
  ansa = time;
  for (int i = 0; i < time; i++) {
    cin >> suuti;
    if (suuti == 2) {
      continue;
    }
    atai = sqrt(suuti);
    for (int ii = 2; ii <= atai + 1; ii++) {
      if (suuti % ii == 0) {
        --ansa;
        break;
      }
    }
  }
  cout << ansa << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  bool sosu[10001];
  for (int i = 2; i <= 10000; i++) {
    sosu[i] = true;
  }
  for (int i = 2; i <= 10000; i++) {
    if (sosu[i] == true) {
      for (int ii = i * 2; ii <= 10000; ii += i) {
        sosu[ii] = false;
      }
    }
  }
  int time, ansa = 0;
  cin >> time;
  int suuti;
  for (int i = 0; i < time; i++) {
    cin >> suuti;
    if (sosu[suuti] == true) {
      ansa++;
    }
  }
  cout << ansa << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> sosu;
  bool check[10000]{false};
  for (int i = 2; i < 10000; ++i) {
    if (!check[i]) {
      sosu.push_back(i);
      for (int j = i * 2; j < 10000; j += i) {
        check[j] = true;
      }
    }
  }
  sosu.push_back(1000000000);
  int time;
  cin >> time;
  int dummy;
  int answer = time;
  int ch;
  vector<int>::iterator place;
  for (int i = 0; i < time; ++i) {
    cin >> dummy;
    if (dummy == 2)
      continue;
    ch = sqrt((double)dummy) + 1;
    for (place = sosu.begin(); *place <= ch; ++place) {
      if (dummy % *place == 0) {
        --answer;
        break;
      }
    }
  }
  cout << answer << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> sosu;
  bool check[10000]{false};
  for (int i = 2; i < 10000; ++i) {
    if (!check[i]) {
      sosu.push_back(i);
      for (int j = i * 2; j < 10000; j += i) {
        check[j] = true;
      }
    }
  }
  sosu.push_back(1000000000);
  int time;
  cin >> time;
  int dummy;
  int answer = time;
  vector<int>::iterator place;
  for (int i = 0; i < time; ++i) {
    cin >> dummy;
    for (place = sosu.begin(); *place * *place <= dummy; ++place) {
      if (dummy % *place == 0) {
        --answer;
        break;
      }
    }
  }
  cout << answer << endl;
  return 0;
}