Problem p02257 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (LL i = 0; i < n; i++)
#define REPR(i, n) for (LL i = n; i >= 0; i--)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define FORR(i, m, n) for (LL i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// typedef LL int;
bool isprime(LL x) {
  if (x == 2)
    return true;
  if (x < 2 || x % 2 == 0)
    return false;
  LL i = 3;
  LL sqrtx = sqrt(x);
  while (i <= sqrtx) {
    if (x % i == 0)
      return false;
    i += 2;
  }
  return true;
}
// max?????§????´???°???vector?????\\????????????
vector<LL> eratos(LL max) {
  vector<LL> primeVec;
  vector<bool> isprime;
  double sqrtmax = sqrt(max);
  isprime.resize(max + 1);
  isprime[0] = false;
  isprime[1] = false;
  FOR(i, 2, max + 1) { isprime[i] = true; }
  FOR(i, 2, sqrtmax) {
    if (isprime[i]) {
      for (int j = 0; i * (j + 2) < max + 1; ++j) {
        isprime[i * (j + 2)] = false;
      }
    }
  }
  REP(i, max + 1) {
    if (isprime[i])
      primeVec.pb(i);
  }
  return primeVec;
}
int main() {
  int n;
  int ans = 0;
  cin >> n;
  while (n--) {
    LL x;
    cin >> x;
    if (isprime(x))
      ans++;
  }
  cout << ans << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (LL i = 0; i < n; i++)
#define REPR(i, n) for (LL i = n; i >= 0; i--)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define FORR(i, m, n) for (LL i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// LL ???????????´????????????????????¢??????
// typedef LL int;
// max?????§????´???°???vector?????\\????????????
vector<LL> eratos(LL max) {
  vector<LL> primeVec;
  vector<bool> isprime;
  double sqrtmax = sqrt(max);
  isprime.resize(max + 1);
  isprime[0] = false;
  isprime[1] = false;
  FOR(i, 2, max + 1) { isprime[i] = true; }
  FOR(i, 2, sqrtmax) {
    if (isprime[i]) {
      for (int j = 0; i * (j + 2) < max + 1; ++j) {
        isprime[i * (j + 2)] = false;
      }
    }
  }
  REP(i, max + 1) {
    if (isprime[i])
      primeVec.pb(i);
  }
  return primeVec;
}
int main() {
  vector<LL> sosuu;
  sosuu = eratos(100000000);

  int n;
  int ans = 0;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    auto reslut = find(all(sosuu), x);
    if (reslut != sosuu.end())
      ans++;
  }
  cout << ans << endl;
}