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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> b = a;
  vector<bool> mp(200005);
  rrep(i, n) {
    if (a[i] == a[i - 1])
      mp[a[i]] = true;
  }
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    int x = a[i];
    b.pop_back();
    if (mp[a[i]]) {
      ans++;
      continue;
    }
    vector<int> rec;
    for (int j = 1; j * j <= x; ++j) {
      if (x % j == 0) {
        rec.push_back(j);
        if (j * j != x)
          rec.push_back(x / j);
      }
    }
    bool ok = false;
    for (int c : rec) {
      if (binary_search(all(b), c)) {
        ok = true;
        break;
      }
    }
    if (ok)
      ans++;
  }
  cout << n - ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> b = a;
  vector<bool> mp(1000005);
  rrep(i, n) {
    if (a[i] == a[i - 1])
      mp[a[i]] = true;
  }
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    int x = a[i];
    b.pop_back();
    if (mp[a[i]]) {
      ans++;
      continue;
    }
    vector<int> rec;
    for (int j = 1; j * j <= x; ++j) {
      if (x % j == 0) {
        rec.push_back(j);
        if (j * j != x)
          rec.push_back(x / j);
      }
    }
    bool ok = false;
    for (int c : rec) {
      if (binary_search(all(b), c)) {
        ok = true;
        break;
      }
    }
    if (ok)
      ans++;
  }
  cout << n - ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

  int n, MAXN = 100010, i, j, k, ans, x;
  cin >> n;
  vector<int> ct(MAXN, 0);
  vector<bool> valid(MAXN, true);

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

  ans = 0;
  for (i = 0; i < MAXN; i++) {
    if (valid[i] && (ct[i] == 1))
      ans++;
    if (ct[i] > 0) {
      for (j = i + i; j < MAXN; j += i)
        valid[j] = false;
    }
  }
  cout << ans << "\n";

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

  int n, MAXN = 1000010, i, j, k, ans, x;
  cin >> n;
  vector<int> ct(MAXN, 0);
  vector<bool> valid(MAXN, true);

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

  ans = 0;
  for (i = 0; i < MAXN; i++) {
    if (valid[i] && (ct[i] == 1))
      ans++;
    if (ct[i] > 0) {
      for (j = i + i; j < MAXN; j += i)
        valid[j] = false;
    }
  }
  cout << ans << "\n";

  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++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) { cin >> v[i]; }
  sort(v.begin(), v.end());
  vector<bool> dp(1000010, true);
  int ans = 0;
  rep(i, n) {
    if (i + 1 < n && v[i] == v[i + 1]) {
      dp[v[i]] = false;
    }
    ans += dp[v[i]];
    for (int j = v[i]; j <= 1000000; j += v[i]) {
      dp[j] = false;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) { cin >> v[i]; }
  sort(v.begin(), v.end());
  vector<bool> dp(1000010, true);
  int ans = 0;
  rep(i, n) {
    if (dp[v[i]] == false) {
      continue;
    }
    if (i + 1 < n && v[i] == v[i + 1]) {
      dp[v[i]] = false;
    }
    ans += dp[v[i]];
    for (int j = v[i]; j <= 1000000; j += v[i]) {
      dp[j] = false;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 2e5 + 5;

int a[N];
int f[N], F[N];

int(((((main)))))() <%
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  for (int x = 1; x < N; x++) {
    for (int y = x; y < N; y += x) {
      F[y] += f[x];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    if (F[x] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
%>

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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 1e6 + 5;

int a[N];
int f[N], F[N];

int(((((main)))))() <%
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  for (int x = 1; x < N; x++) {
    for (int y = x; y < N; y += x) {
      F[y] += f[x];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    if (F[x] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
%>
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
typedef long long ll;
template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL << 60;

const ll MAXN = 200010;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, n) { mp[a[i]]++; }
  vector<ll> d(MAXN);
  for (auto v : mp) {
    for (int i = 1; i * v.first < MAXN; i++) {
      d[i * v.first] += v.second;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (d[a[i]] < 2)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
typedef long long ll;
template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL << 60;

const ll MAXN = 1000010;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, n) { mp[a[i]]++; }
  vector<ll> d(MAXN);
  for (auto v : mp) {
    for (int i = 1; i * v.first < MAXN; i++) {
      d[i * v.first] += v.second;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (d[a[i]] < 2)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int a = 0; a < N; a++)
    cin >> V.at(a);

  vector<int> W(1000000, 0);
  for (int i = 0; i < N; i++) {
    for (int i2 = 1; i2 * V.at(i) <= 1000000; i2++)
      W.at(i2 * V.at(i) - 1)++;
  }
  int ans = 0;
  for (int j = 0; j < N; j++) {
    if (W.at(V.at(j) - 1) == 1)
      ans++;
  }

  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int a = 0; a < N; a++)
    cin >> V.at(a);

  vector<int> W(1000000, 0);
  for (int i = 0; i < N; i++) {
    if (W.at(V.at(i) - 1) >= 1)
      W.at(V.at(i) - 1)++;

    else {
      for (int i2 = 1; i2 * V.at(i) <= 1000000; i2++)
        W.at(i2 * V.at(i) - 1)++;
    }
  }
  int ans = 0;
  for (int j = 0; j < N; j++) {
    if (W.at(V.at(j) - 1) == 1)
      ans++;
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); // 1.15*10^18
const long MAX = 1000000;

int main() {
  long n;
  scanf("%ld", &n);
  std::vector<long> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::vector<bool> cieve(MAX + 1);
  std::sort(a.begin(), a.end());
  long ans = 0;
  for (long i = 0; i < n; i++) {
    if (i == n - 1 || a[i + 1] != a[i]) {
      if (!cieve[a[i]]) {
        ans++;
      }
    }
    for (long j = 1; a[i] * j <= MAX; j++) {
      cieve[a[i] * j] = true;
    }
  }
  printf("%ld\n", ans);
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); // 1.15*10^18
const long MAX = 1000000;

int main() {
  long n;
  scanf("%ld", &n);
  std::vector<long> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::vector<bool> cieve(MAX + 1);
  std::sort(a.begin(), a.end());
  long ans = 0;
  for (long i = 0; i < n; i++) {
    if (i == n - 1 || a[i + 1] != a[i]) {
      if (!cieve[a[i]]) {
        ans++;
      }
    }
    if (!cieve[a[i]]) {
      for (long j = 1; a[i] * j <= MAX; j++) {
        cieve[a[i] * j] = true;
      }
    }
  }
  printf("%ld\n", ans);
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> memo(200001);
  REP(i, N) {
    cin >> A[i];
    memo[A[i]]++;
  }
  int res = 0;
  REP(i, N) {
    if (memo[A[i]] > 1)
      continue;
    if (A[i] == 1) {
      ++res;
      continue;
    }
    if (memo[1]) {
      continue;
    }
    bool ok = true;
    for (ll j = 2; j * j <= A[i]; ++j) {
      if (A[i] % j == 0 && (memo[j] || memo[A[i] / j])) {
        ok = false;
        break;
      }
    }
    if (ok)
      ++res;
  }
  cout << res << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> memo(1000001);
  REP(i, N) {
    cin >> A[i];
    memo[A[i]]++;
  }
  int res = 0;
  REP(i, N) {
    if (memo[A[i]] > 1)
      continue;
    if (A[i] == 1) {
      ++res;
      continue;
    }
    if (memo[1]) {
      continue;
    }
    bool ok = true;
    for (ll j = 2; j * j <= A[i]; ++j) {
      if (A[i] % j == 0 && (memo[j] || memo[A[i] / j])) {
        ok = false;
        break;
      }
    }
    if (ok)
      ++res;
  }
  cout << res << endl;

  return 0;
}
Problem p02642 (C++)

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

using namespace std;

const int maxn = 1000005;

vector<int> mark(maxn);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ++mark[a[i]];
  }
  for (int i = n - 1; i >= 0; i--) {
    int e = a[i];
    if (mark[e] > 1)
      mark[e] = -1;
    for (int j = e + e; j < maxn; j += e) {
      if (mark[j] == -1)
        continue;
      if (mark[j] > 0)
        mark[j] = -1;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (mark[a[i]] != -1)
      ++ans;
  }
  cout << ans << endl;
}


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

using namespace std;

const int maxn = 1000005;

vector<int> mark(maxn);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ++mark[a[i]];
  }
  if (mark[1] > 0) {
    if (mark[1] > 1)
      cout << "0" << endl;
    else if (mark[1] == 1)
      cout << "1" << endl;
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    int e = a[i];
    if (mark[e] > 1)
      mark[e] = -1;
    for (int j = e + e; j < maxn; j += e) {
      if (mark[j] == -1)
        continue;
      if (mark[j] > 0)
        mark[j] = -1;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (mark[a[i]] != -1)
      ++ans;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(M);
  rep(i, n) cin >> a[i];
  for (int j : a) {
    for (int i = j; i <= M; i += j) {
      c[i]++;
    }
  }
  int ans = 0;
  for (int j : a) {
    if (c[j] == 1)
      ans++;
  }
  cout << ans << endl;
}

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

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(M);
  rep(i, n) cin >> a[i];
  for (int j : a) {
    if (c[j] > 0) {
      c[j] = 2;
      continue;
    }
    for (int i = j; i <= M; i += j) {
      c[i]++;
    }
  }
  int ans = 0;
  for (int j : a) {
    if (c[j] == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int y[1000010];
int same[1000010];

bool divisor(int n) {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (y[i] == 1 || y[n / i] == 1) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  memset(y, 0, sizeof y);
  memset(same, 0, sizeof same);
  for (int i = 0; i < n; i++) {
    same[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (divisor(a[i]) == true && same[a[i]] <= 1) {
      ans++;
    }
    y[a[i]] = 1;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int y[1000010];
int same[1000010];

bool divisor(int n) {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (y[i] == 1 || y[n / i] == 1) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int a[200010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  memset(y, 0, sizeof y);
  memset(same, 0, sizeof same);
  for (int i = 0; i < n; i++) {
    same[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (divisor(a[i]) == true && same[a[i]] <= 1) {
      ans++;
    }
    y[a[i]] = 1;
  }
  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<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  long long M = a[n - 1];
  long long d[200000] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 1; j * a[i] <= M; j++) {
      d[a[i] * j]++;
    }
  }

  /*
  for(int i = 1;i <= M;i++){
      cout << d[i] << " ";
  }

  cout << endl;
  */

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

  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  long long M = a[n - 1];
  long long d[1000000 + 10] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 1; j * a[i] <= M; j++) {
      d[a[i] * j]++;
    }
  }

  /*
  for(int i = 1;i <= M;i++){
      cout << d[i] << " ";
  }

  cout << endl;
  */

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

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

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

int main() {
  int n;
  cin >> n;
  int M = 1e05 + 5;
  vector<int> a(n), cnt(M);
  rep(i, n) cin >> a[i];

  for (int x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x)
      cnt[i]++;
  }

  int ans = 0;
  for (int x : a)
    if (cnt[x] == 1)
      ans++;

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


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

int main() {
  int n;
  cin >> n;
  int M = 1e06 + 5;
  vector<int> a(n), cnt(M);
  rep(i, n) cin >> a[i];

  for (int x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x)
      cnt[i]++;
  }

  int ans = 0;
  for (int x : a)
    if (cnt[x] == 1)
      ans++;

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

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll, ll> mA;
  ll ma = 0;
  rep(i, 0, N) {
    cin >> A[i];
    mA[A[i]]++;
    ma = max(ma, A[i]);
  }
  sort(A.begin(), A.end());

  vector<bool> dp(1000010,
                  true); // dp[i] : iより小さいiの約数が存在しなかったらtrue
  for (auto &a : A) {
    ll cur = a;
    int cnt = 2;
    while (cur <= ma) {
      cur = a * cnt;
      dp[cur] = false;
      cnt++;
    }
  }

  ll ans = 0;
  for (auto &a : A) {
    if (dp[a] && mA[a] < 2) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll, ll> mA;
  ll ma = 0;
  rep(i, 0, N) {
    cin >> A[i];
    mA[A[i]]++;
    ma = max(ma, A[i]);
  }
  sort(A.begin(), A.end());

  vector<bool> dp(10000100,
                  true); // dp[i] : iより小さいiの約数が存在しなかったらtrue
  for (auto &a : A) {
    ll cur = a;
    int cnt = 2;
    while (cur <= ma) {
      cur = a * cnt;
      dp[cur] = false;
      cnt++;
    }
  }

  ll ans = 0;
  for (auto &a : A) {
    if (dp[a] && mA[a] < 2) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define N 200010
using namespace std;
int a[N];
map<int, int> mp;
int main() {
  // x+y=a
  // 2x+4y=b
  int n;

  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a, a + n);
    mp.clear();
    for (int i = 0; i < n; i++) {
      if (i != 0 && a[i] == a[i - 1]) {
        mp[a[i]] = 1;
        continue;
      }
      for (int j = a[i] + a[i]; j <= 1000000; j += a[i])
        mp[j] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (!mp[a[i]])
        ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define N 200010
using namespace std;
int a[N];
map<int, int> mp;
int main() {
  // x+y=a
  // 2x+4y=b
  int n;

  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a, a + n);
    mp.clear();
    for (int i = 0; i < n; i++) {
      if (i != 0 && a[i] == a[i - 1]) {
        mp[a[i]] = 1;
        continue;
      }
      if (!mp[a[i]])
        for (int j = a[i] + a[i]; j <= a[n - 1]; j += a[i])
          mp[j] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (!mp[a[i]])
        ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define l_ength size
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &k : a)
    cin >> k;
  sort(a.begin(), a.end());
  int bound = a.back();
  if (a[0] == 1) {
    if (a[1] == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << 1 << endl;
      return 0;
    }
  }
  vector<int> ans(n, 1);
  for (auto itr = a.begin(); itr != a.end(); ++itr) {
    int k = *itr;
    auto tmp = itr;
    ++tmp;
    if (tmp != a.end() and *itr == *tmp) {
      ans[itr - a.begin()] = ans[tmp - a.begin()] = 0;
    }
    int cnt = 1;
    while (k * cnt <= bound) {
      int l = lower_bound(tmp, a.end(), k * cnt) - a.begin();
      int r = upper_bound(tmp, a.end(), k * cnt) - a.begin();
      for (int t = l; l != r and t < r; ++t) {
        ans[t] = 0;
      }
      ++cnt;
    }
  }
  cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define l_ength size
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &k : a)
    cin >> k;
  sort(a.begin(), a.end());
  int bound = a.back();
  if (a[0] == 1) {
    if (a[1] == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << 1 << endl;
      return 0;
    }
  }
  vector<int> ans(n, 1);
  for (auto itr = a.begin(); itr != a.end(); ++itr) {
    int k = *itr;
    auto tmp = itr;
    ++tmp;
    if (ans[itr - a.begin()] == 0)
      continue;
    if (tmp != a.end() and *itr == *tmp) {
      ans[itr - a.begin()] = ans[tmp - a.begin()] = 0;
    }
    int cnt = 1;
    while (k * cnt <= bound) {
      int l = lower_bound(tmp, a.end(), k * cnt) - a.begin();
      int r = upper_bound(tmp, a.end(), k * cnt) - a.begin();
      for (int t = l; l != r and t < r; ++t) {
        ans[t] = 0;
      }
      ++cnt;
    }
  }
  cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i, a, b) for (i = a; i < b; i++)
ll int large = (ll int)1e18;
ll int mod = (ll int)1e9 + 7;
ll int const N = (ll int)1e6 + 10;

ll int mod_exp(ll int x, ll int n) {
  ll int result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x) % mod;
    x = (x * x) % mod;
    n = n / 2;
  }
  return result;
}

ll int mod_inverse(ll int a) { return mod_exp(a, mod - 2); }

ll int const sz = 200005;
ll int seive[sz];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int T, i, j, ij;
  T = 1;
  // cin>>T;
  while (T--) {
    ll int n;
    cin >> n;
    ll int a[n];
    rep(i, 0, n) cin >> a[i];

    ll int num1 = count(a, a + n, 1);
    if (num1 > 1) {
      cout << 0;
    } else if (num1 == 1) {
      cout << 1;
    } else {
      for (ll int i = 0; i < n; i++) {
        for (ll int j = a[i]; j < sz; j += a[i])
          seive[j]++;
      }
      ll int ans = 0;
      rep(i, 0, n) {
        if (seive[a[i]] == 1)
          ans++;
      }

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i, a, b) for (i = a; i < b; i++)
ll int large = (ll int)1e18;
ll int mod = (ll int)1e9 + 7;
ll int const N = (ll int)1e6 + 10;

ll int mod_exp(ll int x, ll int n) {
  ll int result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x) % mod;
    x = (x * x) % mod;
    n = n / 2;
  }
  return result;
}

ll int mod_inverse(ll int a) { return mod_exp(a, mod - 2); }

ll int const sz = N;
ll int seive[sz];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int T, i, j, ij;
  T = 1;
  // cin>>T;
  while (T--) {
    ll int n;
    cin >> n;
    ll int a[n];
    rep(i, 0, n) cin >> a[i];

    ll int num1 = count(a, a + n, 1);
    if (num1 > 1) {
      cout << 0;
    } else if (num1 == 1) {
      cout << 1;
    } else {
      for (ll int i = 0; i < n; i++) {
        for (ll int j = a[i]; j < sz; j += a[i])
          seive[j]++;
      }
      ll int ans = 0;
      rep(i, 0, n) {
        if (seive[a[i]] == 1)
          ans++;
      }

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

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

const int MAXVAL = 1e2;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(MAXVAL + 1);
  vector<int> ans(MAXVAL + 1, 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= MAXVAL; i++) {
    if (cnt[i] > 1)
      ans[i] = 0;
    if (!cnt[i])
      continue;
    for (int j = 2 * i; j <= MAXVAL; j += i)
      ans[j] = 0;
  }
  int answer = 0;
  for (int i = 0; i < n; i++)
    answer += ans[a[i]];
  cout << answer;
  return 0;
}

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

const int MAXVAL = 1e6;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(MAXVAL + 1);
  vector<int> ans(MAXVAL + 1, 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= MAXVAL; i++) {
    if (cnt[i] > 1)
      ans[i] = 0;
    if (!cnt[i])
      continue;
    for (int j = 2 * i; j <= MAXVAL; j += i)
      ans[j] = 0;
  }
  int answer = 0;
  for (int i = 0; i < n; i++)
    answer += ans[a[i]];
  cout << answer;
  return 0;
}
Problem p02642 (C++)

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

#define int long long int
#define MOD 1000000007
#define N 1000003
#define pii pair<int, int>
#define MAX 1000000000000000000
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(), v.end())
#define _rsort(v) sort(v.rbegin(), v.rend())
using namespace std;

int32_t main() {

  int n;
  cin >> n;
  vector<int> v(N, 0), a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = a[i]; j < N; j += a[i]) {
      ++v[j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[a[i]] == 1)
      ans++;
  }
  cout << ans;
  return 0;
}

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

#define int long long int
#define MOD 1000000007
#define N 1000003
#define pii pair<int, int>
#define MAX 1000000000000000000
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(), v.end())
#define _rsort(v) sort(v.rbegin(), v.rend())
using namespace std;

int32_t main() {

  int n;
  cin >> n;
  vector<int> v(N, 0), a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (v[a[i]]) {
      ++v[a[i]];
      continue;
    }
    for (int j = a[i]; j < N; j += a[i]) {
      ++v[j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[a[i]] == 1)
      ans++;
  }
  cout << ans;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T> void print_vec(vector<T> v) {
  for (T i : v)
    cout << i << " ";
  cout << endl;
}
const int MAX_N = 200002;
int f[MAX_N];
set<int> st;
map<int, bool> mp;
int mx;
int dd;
void sieve(vector<int> a) {
  f[0] = -1;
  for (int i : a) {
    if (mp[i]) {
      dd++;
      st.erase(i);
      continue;
    }
    if (f[i])
      continue;
    st.insert(i);
    mp[i] = true;
    f[i] = i;
    for (ll j = i; j <= mx; j += i)
      if (!f[j])
        f[j] = i;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  mx = a[n - 1];
  sieve(a);
  int ans = st.size();
  // if (dd > 0) ans -= dd + 1;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T> void print_vec(vector<T> v) {
  for (T i : v)
    cout << i << " ";
  cout << endl;
}
const int MAX_N = 2000002;
int f[MAX_N];
set<int> st;
map<int, bool> mp;
int mx;
int dd;
void sieve(vector<int> a) {
  f[0] = -1;
  for (int i : a) {
    if (mp[i]) {
      dd++;
      st.erase(i);
      continue;
    }
    if (f[i])
      continue;
    st.insert(i);
    mp[i] = true;
    f[i] = i;
    for (ll j = i; j <= mx; j += i)
      if (!f[j])
        f[j] = i;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  mx = a[n - 1];
  sieve(a);
  int ans = st.size();
  // if (dd > 0) ans -= dd + 1;
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < n; ++i)
#define FORR(i, s, n) for (int i = n - 1; i >= s; --i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define F first
#define S second

ll n, a[200000];
bool t[1000001];

int main(int argc, char **argv) {
  CLEAR(t);
  cin >> n;
  set<ll> s, d;
  REP(i, n) {
    cin >> a[i];
    if (s.count(a[i]) != 0)
      d.insert(a[i]);
    s.insert(a[i]);
  }
  if (s.count(1) != 0) {
    cout << (d.count(1) != 0 ? 0 : 1) << endl;
    return 0;
  }
  sort(a, a + n);
  FOR(i, 2, 1000001)
  if (!t[i] && s.count(i) != 0 && (i == 0 || a[i] != a[i - 1])) {
    for (ll b = 2 * i; b < 1000001; b += i)
      t[b] = true;
  }
  ll res = 0;
  REP(i, n) if (!t[a[i]] && d.count(a[i]) == 0)++ res;
  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < n; ++i)
#define FORR(i, s, n) for (int i = n - 1; i >= s; --i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define F first
#define S second

ll n, a[200000];
bool t[1000001];

int main(int argc, char **argv) {
  CLEAR(t);
  cin >> n;
  set<ll> s, d;
  REP(i, n) {
    cin >> a[i];
    if (s.count(a[i]) != 0)
      d.insert(a[i]);
    s.insert(a[i]);
  }
  if (s.count(1) != 0) {
    cout << (d.count(1) != 0 ? 0 : 1) << endl;
    return 0;
  }
  FOR(i, 2, 1000001) if (!t[i] && s.count(i) != 0) {
    for (ll b = 2 * i; b < 1000001; b += i)
      t[b] = true;
  }
  ll res = 0;
  REP(i, n) if (!t[a[i]] && d.count(a[i]) == 0)++ res;
  cout << res << endl;
  return 0;
}
Problem p02642 (C++)

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

const int M = 200010;

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  vector<int> cnt(M);
  for (int x : A) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x)
      cnt[i]++;
  }

  int ans = 0;
  for (int x : A) {
    if (cnt[x] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


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

const int M = 1000010;

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  vector<int> cnt(M);
  for (int x : A) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x)
      cnt[i]++;
  }

  int ans = 0;
  for (int x : A) {
    if (cnt[x] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

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

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  VI a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  const int MX = a.back();
  VI ck(MX + 100);
  rep2(i, 2, MX + 1) {
    rep(j, n) {
      if (a[j] * i > MX)
        break;
      ck[a[j] * i]++;
    }
  }
  rep(i, n - 1) if (a[i] == a[i + 1]) ck[a[i]]++;

  int ans = 0;
  rep(i, n) if (ck[a[i]] == 0) ans++;
  cout << ans << '\n';
  return 0;
}


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

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  VI a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  const int MX = a.back();
  VI ck(MX + 100);
  rep2(i, 2, MX + 1) {
    rep(j, n) {
      if ((ll)a[j] * i > MX)
        break;
      ck[a[j] * i]++;
    }
  }
  rep(i, n - 1) if (a[i] == a[i + 1]) ck[a[i]]++;

  int ans = 0;
  rep(i, n) if (ck[a[i]] == 0) ans++;
  cout << ans << '\n';
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                                                           \
  cerr << #v << ":";                                                           \
  rep(i, v.size()) cerr << " " << v[i];                                        \
  cerr << endl
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 int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

bool table[1010101];
int cnt[1010101];

void table_init(vector<int> &P) {
  sort(all(P));
  for (auto p : P) {
    if (table[p])
      continue;
    for (int i = 2 * p; i < 1010101; i += p) {
      table[i] = 1;
    }
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  table_init(A);
  int ans = 0;
  for (auto a : A) {
    if (cnt[a] == 1 && !table[a]) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                                                           \
  cerr << #v << ":";                                                           \
  rep(i, v.size()) cerr << " " << v[i];                                        \
  cerr << endl
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 int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

bool table[1010101];
int cnt[1010101];

void table_init(vector<int> &P) {
  sort(all(P));
  P.erase(unique(all(P)), P.end());
  for (auto p : P) {
    if (table[p])
      continue;
    for (int i = 2 * p; i < 1010101; i += p) {
      table[i] = 1;
    }
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  table_init(A);
  int ans = 0;
  for (auto a : A) {
    if (cnt[a] == 1 && !table[a]) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02642 (C++)

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

int main() {
  int n;
  const int max_n = 2 * 1e5;
  cin >> n;
  int a[max_n + 1];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  vector<int> dp(2 * 1e6, 0);
  for (int i = 0; i < n; i++) {
    int now = a[i];
    if (dp[now] == 1) {
      dp[now]++;
      // continue;
      now = 1e7;
    }
    while (now <= 1e6) {
      // if(dp[now] == 1) break;
      dp[now]++;
      now += a[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (dp[a[i]] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int n;
  const int max_n = 2 * 1e5;
  cin >> n;
  int a[max_n + 1];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  vector<int> dp(2 * 1e6, 0);
  for (int i = 0; i < n; i++) {
    int now = a[i];
    if (dp[now] != 0) {
      dp[now]++;
      // continue;
      now = 1e7;
    }
    while (now <= 1e6) {
      // if(dp[now] == 1) break;
      dp[now]++;
      now += a[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (dp[a[i]] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

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

int const MAX = 1000001;
int a[MAX + 5];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    a[x]++;
  }

  int ans = 0;
  for (int i = 1; i < MAX; i++) {
    if (a[i] == 1)
      ans++;
    if (a[i] > 0) {
      for (int j = 2; j * j <= MAX; j++) {
        a[i * j] = 0;
      }
    }
  }

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


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

int const MAX = 1000001;
int a[MAX + 5];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    a[x]++;
  }

  int ans = 0;
  for (int i = 1; i < MAX; i++) {
    if (a[i] == 1)
      ans++;
    if (a[i] > 0) {
      for (int j = 2; i * j <= MAX; j++) {
        a[i * j] = 0;
      }
    }
  }

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

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

#define rep(i, N) for (int i = 0; i < N; i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

const int MAXA = 100000;

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

  vector<int> sieve(MAXA + 1, 0);
  for (auto x : A) {
    if (sieve[x] > 0) {
      sieve[x]++;
      continue;
    }

    for (ll i = x; i <= MAXA; i += x) {
      sieve[i]++;
    }
  }

  int ans = 0;
  for (auto x : A) {
    if (sieve[x] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

const int MAXA = 1000005;

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

  vector<int> sieve(MAXA + 1, 0);
  for (auto x : A) {
    if (sieve[x] > 0) {
      sieve[x]++;
      continue;
    }

    for (ll i = x; i <= MAXA; i += x) {
      sieve[i]++;
    }
  }

  int ans = 0;
  for (auto x : A) {
    if (sieve[x] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define loop(i, x, z) for (int i = x; i < z; i++)
int n, A[200002], cnt[200002], ans = 0;
bool vis[1000002];
int main() {
  cin >> n;
  loop(i, 0, n) cin >> A[i], cnt[A[i]]++;
  sort(A, A + n);
  if (A[0] == 1) {
    if (cnt[1] == 1)
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  loop(i, 0, n) {
    if (!vis[A[i]]) {
      if (cnt[A[i]] == 1)
        ans++;
      for (int j = A[i]; j <= 1000000; j += A[i]) {
        vis[j] = 1;
      }
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define loop(i, x, z) for (int i = x; i < z; i++)
int n, A[200002], cnt[1000002], ans = 0;
bool vis[1000002];
int main() {
  cin >> n;
  loop(i, 0, n) cin >> A[i], cnt[A[i]]++;
  sort(A, A + n);
  if (A[0] == 1) {
    if (cnt[1] == 1)
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  loop(i, 0, n) {
    if (!vis[A[i]]) {
      if (cnt[A[i]] == 1)
        ans++;
      for (int j = A[i]; j <= 1000000; j += A[i]) {
        vis[j] = 1;
      }
    }
  }
  cout << ans;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}

// ミョ(-ω- ?)
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  vector<ll> cnt(1001010, 0);
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  vector<bool> ok(1000005, true);
  for (ll i = 0; i < n; i++) {
    // if(cnt[x] < 1)continue;
    ll x = a[i];
    if (cnt[x] > 1)
      ok[x] = false;
    for (ll i = 2 * x; i < 1000001; i += x)
      ok[i] = false;
  }
  ll res = 0;
  rep(i, n) if (ok[a[i]]) res++;
  cout << res << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}

// ミョ(-ω- ?)
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  vector<ll> cnt(1001010, 0);
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  vector<bool> ok(1000005, true);
  ll x = 0;
  for (ll i = 0; i < 1000001; i++) {
    x = i;
    if (cnt[x] < 1)
      continue;
    // ll x = a[i];
    if (cnt[x] > 1)
      ok[x] = false;
    for (ll i = 2 * x; i < 1000001; i += x)
      ok[i] = false;
  }
  ll res = 0;
  rep(i, n) if (ok[a[i]]) res++;
  cout << res << "\n";
  return 0;
}