prithivMLmods/Coder-Stat huggingface dataset:
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
int n, a[200005], ans, ada[200005];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(ada, 0, sizeof ada);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ada[a[i]]++;
  }
  sort(a + 1, a + n + 1);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ada[a[i]] == -1)
      continue;
    for (int j = 2 * a[i]; j <= a[n]; j += a[i]) {
      ada[j] = -1;
    }
    if (ada[a[i]] == 1)
      ans++;
    ada[a[i]] = -1;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
int n, a[2000005], ans, ada[2000005];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(ada, 0, sizeof ada);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ada[a[i]]++;
  }
  sort(a + 1, a + n + 1);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ada[a[i]] == -1)
      continue;
    for (int j = 2 * a[i]; j <= a[n]; j += a[i]) {
      ada[j] = -1;
    }
    if (ada[a[i]] == 1)
      ans++;
    ada[a[i]] = -1;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(100001, 0);
  rep(i, n) b[a[i]]++;

  ll ans = n;
  rep(i, n) {
    for (ll j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {

        if (a[i] == 1) {
          if (b[j] > 1) {
            ans--;
            break;
          }
        }

        else if (j == 1) {
          if (b[j] > 0 || b[a[i] / j] > 1) {
            ans--;
            break;
          }
        }

        else if (b[j] > 0 || b[a[i] / j] > 0) {
          ans--;
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(1000001, 0);
  rep(i, n) b[a[i]]++;

  ll ans = n;
  rep(i, n) {
    for (ll j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {

        if (a[i] == 1) {
          if (b[j] > 1) {
            ans--;
            break;
          }
        }

        else if (j == 1) {
          if (b[j] > 0 || b[a[i] / j] > 1) {
            ans--;
            break;
          }
        }

        else if (b[j] > 0 || b[a[i] / j] > 0) {
          ans--;
          break;
        }
      }
    }
  }

  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;
const int MAXV = 100010;

int main() {
  int x, n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> nums(MAXV);
  for (int x : a) {
    if (nums[x] >= 1) {
      nums[x] = 2;
      continue;
    }
    for (int j = x; j < MAXV; j += x) {
      nums[j]++;
    }
  }

  int ans = 0;
  rep(i, n) {
    if (nums[a[i]] == 1)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;
const int MAXV = 1000010;

int main() {
  int x, n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> nums(MAXV);
  for (int x : a) {
    if (nums[x] >= 1) {
      nums[x] = 2;
      continue;
    }
    for (int j = x; j < MAXV; j += x) {
      nums[j]++;
    }
  }

  int ans = 0;
  rep(i, n) {
    if (nums[a[i]] == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Unionfind {
  vector<int> par;

  Unionfind(int n) : par(n) {
    for (int i = 0; i < n; ++i)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  const int num = 1000000;
  vector<int> cnt(num + 1, 0);
  vector<int> a(n);

  rep(i, n) {
    cin >> a[i];
    if (cnt[a[i]] != 0) {
      cnt[a[i]] = 10;
      continue;
    }
    for (int j = a[i]; j <= num; j += a[i])
      ++cnt[a[j]];
  }

  int ans = 0;
  rep(i, n) {
    if (cnt[a[i]] == 1)
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Unionfind {
  vector<int> par;

  Unionfind(int n) : par(n) {
    for (int i = 0; i < n; ++i)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  const int num = 1000000;
  vector<int> cnt(num + 1, 0);
  vector<int> a(n);

  rep(i, n) {
    cin >> a[i];
    if (cnt[a[i]] != 0) {
      cnt[a[i]] = 10;
      continue;
    }
    for (int j = a[i]; j <= num; j += a[i])
      ++cnt[j];
  }

  int ans = 0;
  rep(i, n) {
    if (cnt[a[i]] == 1)
      ++ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
int h[1000005];
int a[100005], n, ans, m;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0), std::cout.tie(0);
  std::cin >> n;
  for (int i = 1; i <= n; ++i) {
    std::cin >> a[i];
    ++h[a[i]];
    m = std::max(m, a[i]);
  }
  std::sort(a + 1, a + n + 1);
  n = std::unique(a + 1, a + n + 1) - a - 1;
  for (int i = 1; i <= m; ++i) {
    if (h[i] > 1)
      h[i] = false;
    else if (h[i] == 1)
      ++ans;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = (a[i] << 1); j <= m; j += a[i]) {
      if (h[j] > 0) {
        h[j] = false;
        --ans;
      }
    }
  }
  std::cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
int h[1000005];
int a[200005], n, ans, m;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0), std::cout.tie(0);
  std::cin >> n;
  for (int i = 1; i <= n; ++i) {
    std::cin >> a[i];
    ++h[a[i]];
    m = std::max(m, a[i]);
  }
  std::sort(a + 1, a + n + 1);
  n = std::unique(a + 1, a + n + 1) - a - 1;
  for (int i = 1; i <= m; ++i) {
    if (h[i] > 1)
      h[i] = false;
    else if (h[i] == 1)
      ++ans;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = (a[i] << 1); j <= m; j += a[i]) {
      if (h[j] > 0) {
        h[j] = false;
        --ans;
      }
    }
  }
  std::cout << ans;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

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

  vecll A;
  rep(i, N) {
    ll a;
    cin >> a;
    A.emplace_back(a);
  }
  sort(ALLOF(A));

  ll Amax = A[N - 1];
  vector<bool> dp(A[N - 1], true);
  vector<bool> dirty(A[N - 1], false);

  for (int i = 0; i < N; ++i) {
    ll n = A[i];
    if (dirty[n]) {
      dp[n] = false;
      continue;
    }

    if (dp[n]) {
      ll j = n + n;
      while (j <= Amax) {
        dp[j] = false;
        j += n;
      }
    }

    dirty[n] = true;
  }

  ll ans = 0;
  rep(i, N) {
    if (dp[A[i]])
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

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

  vecll A;
  rep(i, N) {
    ll a;
    cin >> a;
    A.emplace_back(a);
  }
  sort(ALLOF(A));

  ll Amax = A[N - 1];
  vector<bool> dp(Amax + 1, true);
  vector<bool> dirty(Amax + 1, false);

  for (int i = 0; i < N; ++i) {
    ll n = A[i];
    if (dirty[n]) {
      dp[n] = false;
      continue;
    }

    if (dp[n]) {
      ll j = n + n;
      while (j <= Amax) {
        dp[j] = false;
        j += n;
      }
    }

    dirty[n] = true;
  }

  ll ans = 0;
  rep(i, N) {
    if (dp[A[i]])
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, k) for (int i = j; i < k; i++)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), so(1000008, 0);
  rep(i, 0, N) cin >> A[i];

  sort(A.begin(), A.end());

  ll res = 0;

  rep(i, 0, N) {
    bool x = false;
    if (i && A[i - 1] == A[i])
      x = true;
    if (i + 1 != N && A[i + 1] == A[i])
      x = true;
    if (x) {
      for (int j = A[i]; j < 1000007; j += A[i]) {
        so[j] = 1;
      }
      continue;
    }

    if (so[A[i]] == 0) {
      res++;
      for (int j = A[i]; j < 1000007; j += A[i]) {
        so[j] = 1;
      }
    }
  }
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, k) for (int i = j; i < k; i++)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), so(1000008, 0);
  rep(i, 0, N) cin >> A[i];

  sort(A.begin(), A.end());

  ll res = 0;

  rep(i, 0, N) {
    bool x = false;
    if (i && A[i - 1] == A[i])
      x = true;
    if (i + 1 != N && A[i + 1] == A[i])
      x = true;
    if (x && so[A[i]] == 0) {
      for (int j = A[i]; j < 1000007; j += A[i]) {
        so[j] = 1;
      }
      continue;
    }

    if (so[A[i]] == 0) {
      res++;
      for (int j = A[i]; j < 1000007; j += A[i]) {
        so[j] = 1;
      }
    }
  }
  cout << res << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int M = 2 * 1e5 + 10;

int main() {
  int n;
  cin >> n;
  vector<int> unique;
  vector<int> ok(M, 0);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (ok[a] == 0) {
      unique.push_back(a);
      ok[a] = 1;
    } else if (ok[a] == 1) {
      ok[a] = -1;
    }
  }
  for (int i : unique) {
    for (int j = i * 2; j < M; j += i) {
      ok[j] = 0;
    }
  }
  int cnt = 0;
  for (int i = 1; i < M; ++i) {
    if (ok[i] == 1)
      cnt++;
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int M = 2 * 1e6 + 10;

int main() {
  int n;
  cin >> n;
  vector<int> unique;
  vector<int> ok(M, 0);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (ok[a] == 0) {
      unique.push_back(a);
      ok[a] = 1;
    } else if (ok[a] == 1) {
      ok[a] = -1;
    }
  }
  for (int i : unique) {
    for (int j = i * 2; j < M; j += i) {
      ok[j] = 0;
    }
  }
  int cnt = 0;
  for (int i = 1; i < M; ++i) {
    if (ok[i] == 1)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  map<int, int> m;
  for (auto &&i : a) {
    m[i]++;
  }

  sort(a.begin(), a.end());

  int ans = 0;
  for (int i = 0; i < n; i++) {
    m[a[i]]--;
    bool flug = true;

    if (m[a[i]] > 0)
      flug = false;
    else
      for (int j = 1; j * j <= a[i]; j++) {
        if (a[i] % j == 0 && (m[j] > 0 || m[a[i] / j] > 0))
          flug = false;
      }

    if (flug)
      ans++;

    m[a[i]]++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> m(1000000 + 10);
  for (auto &&i : a) {
    m[i]++;
  }

  sort(a.begin(), a.end());

  int ans = 0;
  for (int i = 0; i < n; i++) {
    m[a[i]]--;
    bool flug = true;

    if (m[a[i]] > 0)
      flug = false;
    else
      for (int j = 1; j * j <= a[i]; j++) {
        if (a[i] % j == 0 && (m[j] > 0 || m[a[i] / j] > 0))
          flug = false;
      }

    if (flug)
      ans++;

    m[a[i]]++;
  }

  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  vector<pair<int, int>> B;
  set<int> ans_check;
  B.push_back(make_pair(A.at(0), 1));
  int index = 0;
  for (int i = 1; i < N; i++) {
    if (B.at(index).first == A.at(i))
      B.at(index).second++;
    else {
      index++;
      B.push_back(make_pair(A.at(i), 1));
      ans_check.insert(A.at(i));
    }
  }
  int ans = 0;
  bool check;
  for (int i = 0; i < B.size(); i++) {
    check = true;
    if (B.at(i).second != 1)
      continue;
    else {
      for (int j = 0; j < i; j++) {
        if (B.at(i).first % B.at(j).first == 0) {
          check = false;
          break;
        }
        if (B.at(j).first > sqrt(B.at(i).first)) {
          int tmp = 2;
          while (true) {
            if (tmp > sqrt(B.at(i).first))
              break;
            else if (B.at(i).first % tmp != 0) {
              tmp++;
              continue;
            } else {
              int tmp2 = B.at(i).first / tmp;
              if (ans_check.count(tmp2)) {
                check = false;
                break;
              } else {
                tmp++;
              }
            }
          }
        }
      }
      if (check)
        ans++;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  vector<pair<int, int>> B;
  set<int> ans_check;
  B.push_back(make_pair(A.at(0), 1));
  int index = 0;
  for (int i = 1; i < N; i++) {
    if (B.at(index).first == A.at(i))
      B.at(index).second++;
    else {
      index++;
      B.push_back(make_pair(A.at(i), 1));
      ans_check.insert(A.at(i));
    }
  }
  int ans = 0;
  bool check;
  for (int i = 0; i < B.size(); i++) {
    check = true;
    if (B.at(i).second != 1)
      continue;
    else {
      for (int j = 0; j < i; j++) {
        if (B.at(i).first % B.at(j).first == 0) {
          check = false;
          break;
        }
        if (B.at(j).first > sqrt(B.at(i).first)) {
          int tmp = 2;
          while (true) {
            if (tmp > sqrt(B.at(i).first))
              break;
            else if (B.at(i).first % tmp != 0) {
              tmp++;
              continue;
            } else {
              int tmp2 = B.at(i).first / tmp;
              if (ans_check.count(tmp2)) {
                check = false;
                break;
              } else {
                tmp++;
              }
            }
          }
          break;
        }
      }
      if (check)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;

using namespace std;

const ll M = 1e6;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(M + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (ll j = A[i]; j <= M; j += A[i]) {
      B[j]++;
    }
  }
  int count = 0;
  for (ll a : A) {
    if (B[a] == 1) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;

using namespace std;

const ll M = 1e6;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(M + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    if (B[A[i]] != 0) {
      B[A[i]] = 2;
      continue;
    }
    for (ll j = A[i]; j <= M; j += A[i]) {
      B[j]++;
    }
  }
  int count = 0;
  for (ll a : A) {
    if (B[a] == 1) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 1000099;
int a[N];
int t[M];
int main() {
  ;
  freopen("in.txt", "r", stdin);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    t[a[i]]++;
  }
  int mmax = *max_element(a, a + n);
  sort(a, a + n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    if (t[x] == 0)
      continue;
    for (int j = 2 * x; j < mmax + 10; j += x) {
      t[j] = 0;
    }
    if (t[x] == 1)
      cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 1000099;
int a[N];
int t[M];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    t[a[i]]++;
  }
  int mmax = *max_element(a, a + n);
  sort(a, a + n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    if (t[x] == 0)
      continue;
    for (int j = 2 * x; j < mmax + 10; j += x) {
      t[j] = 0;
    }
    if (t[x] == 1)
      cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

void answer() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  vector<bool> memo(1000005, true);
  vector<int> cnt(1000005, 0);
  rep(i, n) {
    cnt[a[i]]++;
    int b = 2 * a[i];
    while (b <= 1000000) {
      memo[b] = false;
      b += a[i];
    }
  }
  int ans = 0;
  rep(i, n) {
    if (cnt[a[i]] == 1 && memo[a[i]])
      ans++;
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

void answer() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  vector<bool> memo(1000005, true);
  vector<int> cnt(1000005, 0);
  rep(i, n) {
    cnt[a[i]]++;
    int b = 2 * a[i];
    if (cnt[a[i]] == 1) {
      while (b <= 1000000) {
        memo[b] = false;
        b += a[i];
      }
    }
  }
  int ans = 0;
  rep(i, n) {
    if (cnt[a[i]] == 1 && memo[a[i]])
      ans++;
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  return (ret);
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (mp[a[i]] >= 2) {
      continue;
    }
    auto tmp = divisor(a[i]);
    int flag = 0;
    for (auto e : tmp) {
      if (e != a[i] && mp[e]) {
        flag = 1;
        break;
      }
    }
    ans += (1 - flag);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  return (ret);
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> mp(1000001, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (mp[a[i]] >= 2) {
      continue;
    }
    auto tmp = divisor(a[i]);
    int flag = 0;
    for (auto e : tmp) {
      if (e != a[i] && mp[e]) {
        flag = 1;
        break;
      }
    }
    ans += (1 - flag);
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i < (int)(n); i++)

signed main() {
  ll n;
  cin >> n;
  vl vec(n);
  map<ll, ll> mp;
  unordered_set<ll> s;
  rep(i, 0, n) {
    cin >> vec[i];
    mp[vec[i]]++;
    s.insert(vec[i]);
  }
  ll ans = 0;
  rep(i, 0, n) {
    bool ok = true;
    if (mp[vec[i]] > 1) {
      continue;
    }
    for (ll j = (s.count(1) ? 1 : 2); j * j <= vec[i]; j++) {
      if (vec[i] == j)
        continue;
      if (vec[i] % j == 0 && s.count(j)) {
        ok = false;
        break;
      } else if (vec[i] % j == 0 && s.count(vec[i] / j)) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i < (int)(n); i++)

signed main() {
  ll n;
  cin >> n;
  vl vec(n);
  map<ll, ll> mp;
  set<ll> s;
  rep(i, 0, n) {
    cin >> vec[i];
    mp[vec[i]]++;
    s.insert(vec[i]);
  }
  ll ans = 0;
  rep(i, 0, n) {
    bool ok = true;
    if (mp[vec[i]] > 1) {
      continue;
    }
    for (ll j = (s.count(1) ? 1 : 2); j * j <= vec[i]; j++) {
      if (vec[i] == j)
        continue;
      if (vec[i] % j == 0 && s.count(j)) {
        ok = false;
        break;
      } else if (vec[i] % j == 0 && s.count(vec[i] / j)) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

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

  int64_t aMax = 0;
  std::vector<int64_t> a(n);
  for (int i = 0; i != n; i++) {
    std::cin >> a[i];
    if (a[i] > aMax)
      aMax = a[i];
  }

  std::vector<bool> dp(aMax, true);
  std::vector<bool> seen(aMax, false);

  std::sort(a.begin(), a.end());

  int result = 0;

  for (int i = 0; i != n; i++) {
    if (dp[a[i]] == false)
      continue;

    if (seen[a[i]]) {
      dp[a[i]] = false;
      continue;
    }

    seen[a[i]] = true;

    for (int j = 2 * a[i]; j <= aMax; j += a[i]) {
      dp[j] = false;
    }
  }

  for (int i = 0; i != n; i++)
    if (dp[a[i]])
      result++;

  std::cout << result << std::endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

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

  int64_t aMax = 0;
  std::vector<int64_t> a(n);
  for (int i = 0; i != n; i++) {
    std::cin >> a[i];
    if (a[i] > aMax)
      aMax = a[i];
  }

  std::vector<bool> dp(aMax + 1, true);
  std::vector<bool> seen(aMax + 1, false);

  std::sort(a.begin(), a.end());

  int result = 0;

  for (int i = 0; i != n; i++) {
    if (dp[a[i]] == false)
      continue;

    if (seen[a[i]]) {
      dp[a[i]] = false;
      continue;
    }

    seen[a[i]] = true;

    for (int j = 2 * a[i]; j <= aMax; j += a[i]) {
      dp[j] = false;
    }
  }

  for (int i = 0; i != n; i++)
    if (dp[a[i]])
      result++;

  std::cout << result << std::endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define size(x) int(x.size())
#define pb push_back

using namespace std;
using ll = long long;
using pii = pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template <typename... T> void rd(T &...args) { ((cin >> args), ...); }
template <typename... T> void wr(T... args) {
  ((cout << args << " "), ...);
  cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  for (auto &it : a)
    cin >> it, mp[it]++;
  int ans = 0;
  for (auto it : a) {
    mp[it]--;
    for (ll f = 1; f * f <= it; f++) {
      if (it % f == 0) {
        if (mp[f] || mp[it / f])
          goto next;
      }
    }
    ans++;
  next:;
    mp[it]++;
  }

  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define size(x) int(x.size())
#define pb push_back

using namespace std;
using ll = long long;
using pii = pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template <typename... T> void rd(T &...args) { ((cin >> args), ...); }
template <typename... T> void wr(T... args) {
  ((cout << args << " "), ...);
  cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  unordered_map<int, int> mp;
  for (auto &it : a)
    cin >> it, mp[it]++;
  int ans = 0;
  for (auto it : a) {
    mp[it]--;
    for (ll f = 1; f * f <= it; f++) {
      if (it % f == 0) {
        if (mp[f] || mp[it / f])
          goto next;
      }
    }
    ans++;
  next:;
    mp[it]++;
  }

  cout << ans;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll nums[101010];

bool divisor(ll n) {
  vector<ll> div;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (nums[i] > 0)
        return false;
      if (i != n / i) {
        if (nums[n / i] > 0)
          return false;
      }
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    nums[a[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    nums[a[i]]--;
    if (divisor(a[i]))
      ans++;
    nums[a[i]]++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll nums[1010101];

bool divisor(ll n) {
  vector<ll> div;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (nums[i] > 0)
        return false;
      if (i != n / i) {
        if (nums[n / i] > 0)
          return false;
      }
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    nums[a[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    nums[a[i]]--;
    if (divisor(a[i]))
      ans++;
    nums[a[i]]++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool nums[1010101];
ll cnt[1010101];

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    if (nums[a[i]])
      continue;
    for (int j = 2 * a[i]; j < 1010101; j += a[i])
      nums[j] = true;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] == 1 && !nums[a[i]])
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool nums[1010101];
ll cnt[1010101];

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    if (nums[a[i]])
      continue;
    if (cnt[a[i]] > 1)
      continue;
    for (int j = 2 * a[i]; j < 1010101; j += a[i])
      nums[j] = true;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] == 1 && !nums[a[i]])
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

  vector<int> a;
  int a_max = 0;
  int ans = 0;

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

    a.push_back(tmp);
    if (a_max < tmp) {
      a_max = tmp;
    }
  }

  sort(a.begin(), a.end());

  vector<bool> b(a_max + 1);
  vector<int> cnt(a_max + 1, 0);

  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    for (int j = 2; j < a_max; j++) {
      if (i * j > a_max) {
        break;
      }
      b[a[i] * j] = true;
    }
  }

  for (int i = 0; i < n; i++) {
    if (!b[a[i]] && cnt[a[i]] == 1) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

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

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

  vector<int> a;
  int a_max = 0;
  int ans = 0;

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

    a.push_back(tmp);
    if (a_max < tmp) {
      a_max = tmp;
    }
  }

  sort(a.begin(), a.end());

  vector<bool> b(a_max + 1);
  vector<int> cnt(a_max + 1, 0);

  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    for (int j = 2; j <= a_max; j++) {
      if (a[i] * j > a_max) {
        break;
      }
      b[a[i] * j] = true;
    }
  }

  for (int i = 0; i < n; i++) {
    if (!b[a[i]] && cnt[a[i]] == 1) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A)
    cin >> a;
  vector<int> B(1000010);
  for (auto a : A) {
    for (int t = a; t <= 1000000; t += a) {
      B[t] += 1;
    }
  }
  int ans = 0;
  for (auto a : A) {
    if (B[a] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A)
    cin >> a;
  vector<int> B(1000010);
  for (auto a : A) {
    if (B[a] != 0) {
      B[a]++;
      continue;
    }
    for (int t = a; t <= 1000000; t += a) {
      B[t] += 1;
    }
  }
  int ans = 0;
  for (auto a : A) {
    if (B[a] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define dow(i, j, k) for (int i = j; i >= k; i--)
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const int N = 1e6 + 100;

int cnt[N];
int a[N], n;
int ans = 0;
int main() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", &a[i]), cnt[a[i]]++;
  sort(a + 1, a + n + 1);
  rep(i, 1, n) {
    for (int j = 2; a[i] * j <= 1000000; j++)
      cnt[a[i] * j]++;
    if (cnt[a[i]] > 1)
      continue;
    ans++;
    // for (int j = 2; a[i] * j <= 1000000; j++) cnt[a[i] * j]++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define dow(i, j, k) for (int i = j; i >= k; i--)
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const int N = 1e6 + 100;

int cnt[N];
int a[N], n;
int ans = 0;
int main() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", &a[i]), cnt[a[i]]++;
  sort(a + 1, a + n + 1);
  rep(i, 1, n) {
    if (a[i] == a[i - 1])
      continue;
    for (int j = 2; a[i] * j <= 1000000; j++)
      cnt[a[i] * j]++;
    if (cnt[a[i]] > 1)
      continue;
    ans++;
    // for (int j = 2; a[i] * j <= 1000000; j++) cnt[a[i] * j]++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using ll = long long;

using namespace std;

const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> table(12345678, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    table[a[i]]++;
  }

  sort(a.begin(), a.end());

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * a[i] <= 1000000; j++) {
      table[a[i] * j]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (table[a[i]] <= 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using ll = long long;

using namespace std;

const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> table(12345678, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    table[a[i]]++;
  }

  sort(a.begin(), a.end());

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 2; a[i] * j <= a[n - 1]; j++) {
      table[a[i] * j]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (table[a[i]] <= 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  bool b[1000001];
  for (int i = 0; i < 1000001; i++) {
    b[i] = true;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool temp = true;
    if (n != n - 1) {
      if (a[i] == a[i + 1])
        temp = false;
    }
    if (b[a[i]] and temp)
      ans++;
    for (int j = a[i]; j <= 1000000; j += a[i]) {
      b[j] = false;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  bool b[1000001];
  for (int i = 0; i < 1000001; i++) {
    b[i] = true;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool temp = true;
    if (n != n - 1) {
      if (a[i] == a[i + 1])
        temp = false;
    }
    if (b[a[i]] and temp)
      ans++;
    if (!b[a[i]])
      continue;
    for (int j = a[i]; j <= 1000000; j += a[i]) {
      b[j] = false;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define sws                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for (int i = 0; i < n; i++)

int main() {

  int n;
  cin >> n;
  bool divs[1000005];
  map<int, int> m;
  vi a(n);
  memset(divs, true, sizeof(divs));
  fo(i, n) {
    cin >> a[i];
    m[a[i]]++;
    for (int j = a[i] * 2; j < 1000005; j += a[i]) {
      divs[j] = false;
    }
  }

  int ans = 0;
  fo(i, n) if (divs[a[i]] and m[a[i]] == 1) {
    // cout << a[i] << endl;
    ans++;
  }

  cout << ans << endl;

  return 0;
}

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

#define sws                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for (int i = 0; i < n; i++)

int main() {

  int n;
  cin >> n;
  bool divs[1000005];
  map<int, int> m;
  vi a(n);
  memset(divs, true, sizeof(divs));
  fo(i, n) {
    cin >> a[i];
    if (++m[a[i]] > 1)
      continue;
    for (int j = a[i] * 2; j < 1000005; j += a[i]) {
      divs[j] = false;
    }
  }

  int ans = 0;
  fo(i, n) if (divs[a[i]] and m[a[i]] == 1) {
    // cout << a[i] << endl;
    ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
// #include<bits/stdc++.h>
// #define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORE(i, a, b) for (int i = (a); i <= (b); i++)

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

bool dp[100010];
int arr[20010];

int main() {
  // IOS
  int n;
  cin >> n;
  int p;
  int max = -1;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    if (p > max)
      max = p;
    arr[i] = p;
  }
  sort(arr + 1, arr + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (arr[i] == arr[i - 1]) {
      dp[arr[i]] = true;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[arr[i]] == false) {
      cnt++;
    }
    if (arr[i] != arr[i - 1]) {
      for (int j = 2 * arr[i]; j <= max; j += arr[i]) {
        dp[j] = true;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
// #include<bits/stdc++.h>
// #define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORE(i, a, b) for (int i = (a); i <= (b); i++)

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

bool dp[10000010];
int arr[2000010];

int main() {
  // IOS
  int n;
  cin >> n;
  int p;
  int max = -1;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    if (p > max)
      max = p;
    arr[i] = p;
  }
  sort(arr + 1, arr + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (arr[i] == arr[i - 1]) {
      dp[arr[i]] = true;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[arr[i]] == false) {
      cnt++;
    }
    if (arr[i] != arr[i - 1]) {
      for (int j = 2 * arr[i]; j <= max; j += arr[i]) {
        dp[j] = true;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pii pair<int, int>

int N;
int A[200010];
int mem[1000010];
int num[1000010];

signed main() {
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    num[A[i]]++;
  }

  sort(A, A + N);

  int ans = 0;
  rep(i, N) {
    if (mem[A[i]] == 0 && num[A[i]] == 1)
      ans++;
    for (int j = A[i]; j <= 1000000; j += A[i])
      mem[j] = 1;
  }

  cout << ans << endl;

  return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pii pair<int, int>

int N;
int A[200010];
int mem[1000010];
int num[1000010];

signed main() {
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    num[A[i]]++;
  }

  sort(A, A + N);

  int ans = 0;
  rep(i, N) {
    if (mem[A[i]] == 0 && num[A[i]] == 1)
      ans++;
    if (mem[A[i]] == 0)
      for (int j = A[i]; j <= 1000000; j += A[i])
        mem[j] = 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int64_t INF = 1LL << 60;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int m = *max_element(A.begin(), A.end());
  sort(A.begin(), A.end());

  vector<bool> ok(999999, true);

  for (int i = 0; i < N; i++) {
    if (A[i] == A[i + 1]) {
      ok[A[i]] = false;
    }
    for (int j = 2; j <= (m + A[i] - 1) / A[i]; j++) {
      ok[A[i] * j] = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (ok[A[i]]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int64_t INF = 1LL << 60;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int m = *max_element(A.begin(), A.end());
  sort(A.begin(), A.end());

  vector<bool> ok(10000000, true);

  for (int i = 0; i < N; i++) {
    if (A[i] == A[i + 1]) {
      ok[A[i]] = false;
    }
    for (int j = 2; j <= (m + A[i] - 1) / A[i]; j++) {
      ok[A[i] * j] = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (ok[A[i]]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {
  int n;
  cin >> n;
  int m = 100000001;
  vector<int> ans(m, 0), a(n, 0);
  int maxidx = 0;
  rep(i, n) {
    cin >> a[i];
    maxidx = max(a[i], maxidx);
  }

  set<int> nums;
  for (auto i : a) {
    if (ans[i] != 0) {
      ans[i] = 2;
      continue;
    }
    for (int j = i; j < m; j += i) {
      ans[j] += 1;
    }
  }
  int cnt = 0;
  for (auto i : a)
    if (ans[i] == 1)
      cnt++;
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {
  int n;
  cin >> n;
  int m = 1000005;
  vector<int> ans(m, 0), a(n, 0);
  int maxidx = 0;
  rep(i, n) {
    cin >> a[i];
    maxidx = max(a[i], maxidx);
  }

  set<int> nums;
  for (auto i : a) {
    if (ans[i] != 0) {
      ans[i] = 2;
      continue;
    }
    for (int j = i; j < m; j += i) {
      ans[j] += 1;
    }
  }
  int cnt = 0;
  for (auto i : a)
    if (ans[i] == 1)
      cnt++;
  cout << cnt << endl;
}