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

#include <cmath>
#include <cstdio>

int main(void) {
  int n, x;
  int counter = 0;
  int is_prime = 0;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x == 2) {
      counter++;
      continue;
    }
    if (!(x % 2) || x == 1)
      continue;
    is_prime = 1;
    for (int j = 2; j < sqrt(x) + 1; j++) {
      if (x % j == 0) {
        is_prime = 0;
        break;
      }
    }
    if (is_prime)
      counter++;
  }
  printf("%d\\n", counter);
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>

int main(void) {
  int n, x;
  int counter = 0;
  int is_prime = 0;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x == 2) {
      counter++;
      continue;
    }
    if (!(x % 2) || x == 1)
      continue;
    is_prime = 1;
    for (int j = 2; j < x; j++) {
      if (x % j == 0) {
        is_prime = 0;
        break;
      }
    }
    if (is_prime)
      counter++;
  }
  printf("%d\\n", counter);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int maxn = 1e8 + 8;

int a[10000 + 8];
int n, v, j;

void insertSort(int a[]) {
  for (int i = 1; i < n; ++i) {
    v = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
  }
}
bool judge(int x) {
  if (x == 2)
    return true;
  for (int i = 2; i <= (int)sqrt(x); ++i) {
    if (x % i == 0)
      return false;
  }
  return true;
}
int main() {
  memset(a, 0, sizeof a);

  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  insertSort(a); //??¶??´?????????O(n^2)

  /* for(int i = 0; i < n; ++i){
       if(i) printf(" ");
       printf("%d",a[i]);
   }
   printf("\\n");*/

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (judge(a[i]))
      cnt++;
  }
  printf("%d\\n", cnt);
  return 0;
}
/*
11
12
13
14
15
16
17
7
8
9
10
11
*/

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int maxn = 1e8 + 8;

int a[1000 + 8];
int n, v, j;

void insertSort(int a[]) {
  for (int i = 1; i < n; ++i) {
    v = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
  }
}
bool judge(int x) {
  if (x == 2)
    return true;
  if (x < 2)
    return false;
  for (int i = 2; i <= (int)sqrt(x); ++i) {
    if (x % i == 0)
      return false;
  }
  return true;
}
int main() {
  memset(a, 0, sizeof a);

  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  insertSort(a); //??¶??´?????????O(n^2)

  /* for(int i = 0; i < n; ++i){
       if(i) printf(" ");
       printf("%d",a[i]);
   }
   printf("\\n");*/

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (judge(a[i]))
      cnt++;
  }
  printf("%d\\n", cnt);
  return 0;
}
/*
11
12
13
14
15
16
17
7
8
9
10
11
*/
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, b, d = 0;
  cin >> n;
  while (n > 0) {
    n--;
    cin >> b;
    if (snt(b))
      d++;
  }
  cout << d << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool snt(int a) {
  if (a == 2 || a == 3)
    return true;
  if (a < 2)
    return false;
  for (int i = 2; i < a; i++)
    if (a % i == 0)
      return false;
  return true;
}

int main() {
  int n, b, d = 0;
  cin >> n;
  while (n > 0) {
    n--;
    cin >> b;
    if (snt(b))
      d++;
  }
  cout << d << endl;

  return 0;
}
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 <= sqrt(x)) {
    if (x % i == 0)
      return false;
    i = i + 2;
  }
  return true;
}

int main(void) {
  // Here your code !
  int n, x, ct = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (isPrime(x))
      ct++;
  }
  cout << ct << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, s, j, ct = 0, p[10000];

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

  for (int i = 0; i < n; i++) {
    // s = sqrt(p[i]);
    j = 2;
    while (p[i] % j > 0) {
      // cout << p[i] << " " << j << " " << ct << endl;
      j++;
    }
    if (j == p[i])
      ct++;
  }

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

#include <iostream>
using namespace std;

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans += isPrime(x);
  }
  cout << ans << "\\n";
}

Error: MLE

Fixed submission:

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

#define max 100000001

bool isPrime[max];

void make_isPrime(int MAX) {
  for (int i = 0; i < MAX; i++)
    isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;

  for (int i = 2; i < MAX; i++) {
    if (isPrime[i])
      for (int j = 2; i * j <= MAX; j++)
        isPrime[i * j] = false;
  }
}

int main() {
  make_isPrime(100000001);
  int n;
  cin >> n;
  vector<int> input;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    input.push_back(tmp);
  }
  int ans = 0;
  for (int i = 0; i < input.size(); i++) {
    if (isPrime[input[i]])
      ans++;
  }
  cout << ans << "\\n";
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <cmath>
#include <iostream>

using namespace std;
int main() {
  int n, x;
  int cnt = 0;
  int flag = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;

    if (x == 2)
      flag = 0;
    else if (x % 2 == 0)
      flag = 1;

    else {
      for (int j = 2; j <= sqrt(x); j++) {
        if (x % j == 0) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      cnt++;
    flag = 0;
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;
int main() {
  int n, x;
  int cnt = 0;
  int flag = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;

    if (x == 2)
      flag = 0;
    else if (x % 2 == 0)
      flag = 1;

    else {
      for (int j = 2; j < x; j++) {
        if (x % j == 0) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      cnt++;
    flag = 0;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
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 x;
  int count = 0;

  cin >> n;

  while (n > 0) {
    cin >> x;

    if (isprime(x))
      count++;

    n--;
  }

  cout << count << endl;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {

  bool p[10001] = {false};
  p[2] = true;
  p[3] = true;

  for (int i = 3; i < 10001; i += 2) {
    bool f = false;
    for (int j = 3; j <= sqrt(i); j += 2) {
      if (i % j == 0) {
        f = true;
        break;
      }
    }
    if (!f)
      p[i] = true;
  }

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

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

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

unsigned int s[100000000 / 8 + 1];

int bget(int n) { return (s[n / 32] >> (n % 32)) & 1; }

int bset(int n) { s[n / 32] |= 1 << (n % 32); }

void sieve(int n) {
  int m = sqrt(n);
  bset(0);
  bset(1);
  for (int k = 2; k <= m; k++) {
    if (bget(k))
      continue;
    for (int i = 2 * k; i <= n; i += k) {
      bset(i);
    }
  }
}

int main(void) {
  int n;
  sieve(100000000);
  scanf("%d", &n);
  int count = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (!bget(x))
      count++;
  }
  printf("%d\\n", count);
  return 0;
}

Error: TLE

Fixed submission:

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

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

int main(void) {
  int n;
  scanf("%d", &n);
  int count = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (isprime(x))
      count++;
  }
  printf("%d\\n", count);
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

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

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

int main() {
  int num;
  int count = 0; // 素数の数をカウントする

  while (cin >> num) {
    if (PrimeNumbers2(num))
      count++;
  }

  cout << count << endl;

  return 0;
}


Error: WA

Fixed submission:

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

bool PrimeNumbers(int x) {
  bool Num[x + 1];

  Num[0] = false;
  Num[1] = false;

  /*Numをtrueで初期化。全てが素数候補*/
  for (int i = 2; i <= x; i++) {
    Num[i] = true;
  }

  /*エラトステネスの篩*/
  for (int i = 2; i <= sqrt(x); i++) {
    if (Num[i] == true) // 素数の場合
    {
      for (int j = i; j <= x / i; j++) // 2*2,2*3,,,2*50まで除外されているので
      {
        Num[j * i] =
            false; // 次に3の倍数を削除するとき、3*2をやらないためにj=iとする
        if (Num[x] == false) // Num[x]が素数でなかったら終了
          return Num[x];
      }
    }
  }

  return Num[x];
}

// エラトステネスの篩による素数判定プログラム
int main() {
  int num;
  int count = 0; // 素数の数をカウントする

  while (cin >> num) {
    if (PrimeNumbers(num))
      count++;
  }

  cout << count << endl;

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


#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
int a[10000];
int s = 0;
int b = 0;

int main() {
  cin >> n;

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

  for (int i = 0; i < n; i++) {
    b = sqrt(a[i]);
    if (a[i] == 2 || a[i] == 3)
      s++;
    for (int j = 2; j < b + 1; j++) {

      if (a[i] % j == 0)
        break;
      if (j == b)
        s++;
    }
  }

  cout << s << endl;

  return 0;
}

Error: MLE

Fixed submission:


#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
int c = 0;
int a[10000];
int b[100000000];

int main() {
  cin >> n;
  b[0] = 1;
  b[1] = 1;
  for (int i = 2; i < 100000000; i++) {
    b[i] = 1;
  }

  for (int i = 2; i < 10000; i++) {
    if (b[i] == 1) {
      for (int j = 2; j < 10000; j++)
        b[i * j] = -1;
    }
  }

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

  for (int i = 0; i < n; i++) {
    if (b[a[i]] == 1) {
      c++;
    }
  }

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

#include <cmath>
#include <iostream>

int main() {
  int n;
  bool if_p[10000];
  for (int i = 0; i < 10000; i++)
    if_p[i] = true;
  if_p[0] = false;
  if_p[1] = true;
  for (int lim = 1; lim < 10000; lim = lim * (lim + 2)) {
    for (int iter = 0; iter <= lim; iter++) {
      if (if_p[iter])
        for (int i = 2; i * (iter + 1) <= 10000; i++)
          if_p[i * (iter + 1) - 1] = false;
    }
  }
  std::cin >> n;
  int count = 0;
  for (; n--;) {
    int input;
    std::cin >> input;
    bool b = true;
    ;
    for (int i = 0; i <= sqrt(input) - 1; i++) {
      if (if_p[i] && !(input % (i + 1))) {
        b = false;
        break;
      }
    }
    if (b)
      count++;
  }
  std::cout << count << std::endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

int main() {
  int n;
  bool if_p[10000];
  for (int i = 0; i < 10000; i++)
    if_p[i] = true;
  if_p[0] = false;
  if_p[1] = true;
  for (int lim = 1; lim < 10000; lim = lim * (lim + 2)) {
    for (int iter = 0; iter <= lim; iter++) {
      if (if_p[iter])
        for (int i = 2; i * (iter + 1) <= 10000; i++)
          if_p[i * (iter + 1) - 1] = false;
    }
  }
  std::cin >> n;
  int count = 0;
  for (; n--;) {
    int input;
    std::cin >> input;
    if (if_p[input - 1])
      count++;
  }
  std::cout << count << std::endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int isPrime(int x) {
  int i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int n, a, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (isPrime(a))
      sum++;
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 10005

int isPrime[MAX], p[MAX], tot;
void init() {
  tot = 0;
  for (int i = 2; i < MAX; i++)
    isPrime[i] = 1;
  for (int i = 2; i < MAX; i++) {
    if (isPrime[i])
      p[tot++] = i;
    for (int j = 0; j < tot && i * p[j] < MAX; j++) {
      isPrime[i * p[j]] = 0;
      if (i % p[j] == 0)
        break;
    }
  }
}
int main() {
  int n, a, sum = 0;
  cin >> n;
  init();
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (isPrime[a])
      sum++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  return true;
}

int main() {
  int n, k; // k個の整数
  int count = 0;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    cin >> n;
    if (IsPrime(n)) {
      count++;
    }
  }
  cout << count << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

#define Max 1000000

int isPrime[Max];

int main() {
  int num;
  int i, j, k;
  int count = 0;

  // 配列の初期化
  isPrime[0] = isPrime[1] = 0;
  for (i = 2; i < Max; ++i) {
    isPrime[i] = 1;
  }

  for (i = 2; i < Max; i++) {
    if (isPrime[i] == 1) {
      for (j = 2; i * j <= Max; ++j) {
        isPrime[i * j] = 0;
      }
    }
  }

  cin >> num;
  for (i = 0; i < num; ++i) {
    cin >> k;
    if (isPrime[k] == 1) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int cnt = 0, x, n, i, j;
  bool flg;
  double rootx;
  int rootintx;
  cin >> n;
  for (i = 0; i < n; i++) {
    flg = true;
    cin >> x;
    if (x == 2) {
      cnt++;
      continue;
    }
    if (x < 2 || !(x % 2)) {
      continue;
    }
    rootx = sqrt(x);
    rootx = ceil(rootx);
    rootintx = int(rootx);
    for (j = 2; j <= rootintx; j++) {
      if (!(x % j)) {
        flg = false;
        break;
      }
    }
    if (flg)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int num[10000], i, n, j, cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> num[i];
  }
  for (i = 0; i < n; i++) {
    if (num[i] == 2) {
      cnt++;
    } else {
      for (j = 2; j < num[i]; j++) {
        if ((num[i] % j) == 0)
          break;
      }
      if (j == num[i])
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
inline int getprime(int x) {
  int i = sqrt(x);
  while (i > 1) {
    if (x % i == 0)
      return 0;
    else
      i--;
  }
  return 1;
}
int main() {
  int n;
  cin >> n;
  int x;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cnt += getprime(x);
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
inline int getprime(int x) {
  int i = x / 2;
  while (i > 1) {
    if (x % i == 0)
      return 0;
    else
      i--;
  }
  return 1;
}
int main() {
  int n;
  cin >> n;
  int x;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cnt += getprime(x);
  }
  cout << cnt << endl;
  return 0;
}
Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main(void) {
  int n;
  int ans = 0;

  cin >> n;

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

    int j = 2;
    for (; j <= sqrt(x); j++) {
      if (x % j == 0)
        break;
    }
    if (j > sqrt(x)) {
      ans++;
    }
  }

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

  return 0;
}

Error: MLE

Fixed submission:

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

const int N = 100000002;

int prime[N];

int main(void) {
  int n;
  int ans = 0;

  cin >> n;

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

  /*
  for(int i=0; i<n; i++){
          printf("%d:%d\\n", i, prime[i]);
  }
  */

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

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

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

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

int main(void) {
  int n;
  int ans = 0;

  cin >> n;

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

    if (x == 2)
      ans++;
    if (x % 2 == 0)
      continue;
    int j = 3;
    for (; j <= sqrt(x); j += 2) {
      if (x % j == 0)
        break;
    }
    if (j > sqrt(x)) {
      ans++;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n;
  int ans = 0;

  cin >> n;

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

    int j = 2;
    for (; j < x; j++) {
      if (x % j == 0)
        break;
    }
    if (j == x) {
      ans++;
    }
  }

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

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

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

int main() {
  int N, m, num = 0;
  double d;
  cin >> N;
  int j;
  for (int i = 0; i < N; i++) {
    cin >> m;
    d = sqrt(m);
    for (j = 2; j <= (int)d && m % j; j++)
      ;
    if (d < j) {
      num++;
    }
  }
  cout << num << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N, m, num = 0;
  cin >> N;
  int j;
  for (int i = 0; i < N; i++) {
    cin >> m;
    for (j = 2; j < m && m % j; j++)
      ;
    if (m == j) {
      num++;
    }
  }
  cout << num << endl;
}
Problem p02257 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

int main() {
  int N;
  cin >> N;
  int numberOfPrimeNumber = 0;

  for (int i = 0; i < N; i++) {
    int primeNumber;
    cin >> primeNumber;

    if (isPrime(primeNumber)) {
      numberOfPrimeNumber++;
    }
  }

  cout << numberOfPrimeNumber << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  for (int i = 0; i < N; i++) {
    int primeNumber;
    cin >> primeNumber;
    for (int j = 2; j < primeNumber; j++) {
      if (primeNumber % j == 0) {
        numberOfPrimeNumber--;
        break;
      }
    }
  }

  cout << numberOfPrimeNumber << endl;

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

#include <iostream>
using namespace std;

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

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

// bool prinmes[100000000]={true};

bool IsPrime(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      count++;
    }
    if (count > 2) {
      return false;
    }
  }
  return (count == 2);
}

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

#include <iostream>
#include <math.h>
using namespace std;
//---------------------------------------
bool check_sosu(int x);
//---------------------------------------

int main(void) {
  int num;
  int num_sosu = 0;

  cin >> num;

  for (int i = 0; i < num; i++) {
    int a;
    cin >> a;
    if (check_sosu(a)) { // check_sosu(a)????´???°??????true
      num_sosu++;
    }
  }

  cout << num_sosu << endl;

  return 0;
}
//--------------------------------------------
bool check_sosu(int x) {
  int amari_zero_num = 0;

  for (int i = 1; i <= sqrt(x); i++) {
    int amari = x % i;
    if (!amari) {
      amari_zero_num++;
    }
  }
  if (amari_zero_num == 1) {
    return true;
  }
  return false;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
//---------------------------------------
bool check_sosu(int x);
//---------------------------------------

int main(void) {
  int num;
  int num_sosu = 0;

  cin >> num;

  for (int i = 0; i < num; i++) {
    int a;
    cin >> a;
    if (check_sosu(a)) { // check_sosu(a)????´???°??????true
      num_sosu++;
    }
  }

  cout << num_sosu << endl;

  return 0;
}
//--------------------------------------------
bool check_sosu(int x) {
  int amari_zero_num = 0;

  for (int i = 1; i <= x; i++) {
    int amari = x % i;
    if (!amari) {
      amari_zero_num++;
    }
  }
  if (amari_zero_num == 2) {
    return true;
  }
  return false;
}