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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e5 + 7
#define lim (lld)1e9 + 7
#define MAX2 (int)1e6 + 9
#define ff first
#define ss second
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

const lld mod = lim;

lld power(lld x, lld y, lld p) {
  lld res = 1;
  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

int extend_gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = extend_gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

int rowNum[] = {-1, 0, 0, 1};
int colNum[] = {0, -1, 1, 0};
std::vector<int> vis(MAX2);

int main() {
  fastio int n, ans = 0;
  cin >> n;

  std::vector<int> v(n);

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

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

  for (int i = 0; i < n; i++) {
    for (int j = v[i]; j <= MAX2; j += v[i]) {
      vis[j]++;
    }
  }

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

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e5 + 7
#define lim (lld)1e9 + 7
#define MAX2 (int)1e6 + 9
#define ff first
#define ss second
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

const lld mod = lim;

lld power(lld x, lld y, lld p) {
  lld res = 1;
  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

int extend_gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = extend_gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

int rowNum[] = {-1, 0, 0, 1};
int colNum[] = {0, -1, 1, 0};
std::vector<int> vis(MAX2);

int main() {
  fastio int n, ans = 0;
  cin >> n;

  std::vector<int> v(n);

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

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

  for (int i = 0; i < n; i++) {
    for (int j = v[i]; j <= v[n - 1]; j += v[i]) {
      vis[j]++;
    }
  }

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

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

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

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int ans, N, A[200001];
int a[200001];
bool f[200001];

int main() {
  int b, i, j, m;
  cin >> N;

  rep(1, i, N + 1) {
    cin >> A[i];
    a[A[i]]++;
    m = max(m, A[i]);
  }
  rep(1, i, N + 1) {
    if (a[A[i]] > 1)
      f[A[i]] = true;
    for (j = A[i] * 2; j < m + 1; j += A[i])
      f[j] = true;
  }

  rep(1, i, N + 1) {
    if (!f[A[i]])
      ans++;
  }

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

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

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int ans, N, A[200001];
int a[1000001];
bool f[1000001];

int main() {
  int b, i, j, m;
  cin >> N;

  rep(1, i, N + 1) {
    cin >> A[i];
    a[A[i]]++;
    m = max(m, A[i]);
  }
  rep(1, i, N + 1) {
    if (a[A[i]] > 1)
      f[A[i]] = true;
    for (j = A[i] * 2; j < m + 1; j += A[i])
      f[j] = true;
  }

  rep(1, i, N + 1) {
    if (!f[A[i]])
      ans++;
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
  const int MAX_SIZE = 1000005;
  bool num[MAX_SIZE];
  rep(i, 0, MAX_SIZE) num[i] = false;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  int cnt = 0;
  // エラトステネスの篩
  rep(i, 0, n) {
    if (num[a[i]] == true)
      continue;
    // 重複判定、昇順なのでこれでOK
    if (!(i < n - 1 && a[i] == a[i + 1]))
      cnt++;

    for (int j = a[i]; i < MAX_SIZE; j += a[i])
      num[j] = true;
  }
  cout << cnt;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
  const int MAX_SIZE = 1000005;
  bool num[MAX_SIZE];
  rep(i, 0, MAX_SIZE) num[i] = false;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  int cnt = 0;
  // エラトステネスの篩
  rep(i, 0, n) {
    if (num[a[i]] == true)
      continue;
    // 重複判定、昇順なのでこれでOK
    if (!(i < n - 1 && a[i] == a[i + 1]))
      cnt++;

    for (int j = a[i]; j < MAX_SIZE; j += a[i])
      num[j] = true;
  }
  cout << cnt;

  return 0;
}
Problem p02642 (C++)

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

#define ll long long

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;

  cin >> n;

  vector<ll> d(n);
  ll sz = 1000000;
  vector<bool> arr(sz, true);
  unordered_set<ll> st;

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

    if (st.find(d[i]) == st.end()) {
      st.insert(d[i]);

      for (ll j = d[i] * 2; j < sz; j += d[i]) {
        arr[j] = false;
      }
    } else {
      arr[d[i]] = false;
    }
  }

  ll ans = 0;

  for (ll i = 0; i < (ll)(d.size()); i++) {
    if (arr[d[i]]) {
      ans++;
    }
  }

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

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

#define ll long long

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;

  cin >> n;

  vector<ll> d(n);
  ll sz = 1000001;
  vector<bool> arr(sz, true);
  unordered_set<ll> st;

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

    if (st.find(d[i]) == st.end()) {
      st.insert(d[i]);

      for (ll j = d[i] * 2; j < sz; j += d[i]) {
        arr[j] = false;
      }
    } else {
      arr[d[i]] = false;
    }
  }

  ll ans = 0;

  for (ll i = 0; i < (ll)(d.size()); i++) {
    if (arr[d[i]]) {
      ans++;
    }
  }

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int T = 0; T < t; T++) {
    ll n, ans = 0;
    cin >> n;
    ll a[n];
    int b[1000001] = {0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    for (int i = 1; i < n; i++) {
      if (a[i] == a[i - 1])
        b[a[i]] = 1;
    }
    for (int i = 0; i < n; i++) {
      if (b[a[i]] != 1)
        ans++;
      for (int j = 2 * a[i]; j <= 1000000; j += a[i]) {
        if (b[j] == 0)
          b[j] = 1;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int T = 0; T < t; T++) {
    ll n, ans = 0;
    cin >> n;
    ll a[n];
    int b[1000001] = {0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    for (int i = 1; i < n; i++) {
      if (a[i] == a[i - 1])
        b[a[i]] = 1;
    }
    for (int i = 0; i < n; i++) {
      if (b[a[i]] != 1)
        ans++;
      if (a[i] != a[i - 1]) {
        for (int j = 2 * a[i]; j <= 1000000; j += a[i]) {
          if (b[j] == 0)
            b[j] = 1;
        }
      }
    }
    std::cout << ans << std::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++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100005;
int a[MAX_N], cnt[1000005];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  if (cnt[1] == 1) {
    cout << "1" << endl;
    return 0;
  }
  if (cnt[1] > 1) {
    cout << "0" << endl;
    return 0;
  }
  bool flag = true;
  int ans = 0;
  rep(i, n) {
    flag = true;
    if (cnt[a[i]] > 1)
      flag = false;
    for (int j = 2; j * j <= a[i]; ++j) {
      if (a[i] % j == 0) {
        if (cnt[j] > 0) {
          flag = false;
          break;
        }
        if (cnt[a[i] / j] > 0) {
          flag = false;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }
  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;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 200005;
int a[MAX_N], cnt[1000005];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  if (cnt[1] == 1) {
    cout << "1" << endl;
    return 0;
  }
  if (cnt[1] > 1) {
    cout << "0" << endl;
    return 0;
  }
  bool flag = true;
  int ans = 0;
  rep(i, n) {
    flag = true;
    if (cnt[a[i]] > 1)
      flag = false;
    for (int j = 2; j * j <= a[i]; ++j) {
      if (a[i] % j == 0) {
        if (cnt[j] > 0) {
          flag = false;
          break;
        }
        if (cnt[a[i] / j] > 0) {
          flag = false;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <vector>

typedef long long ll;

int N;
ll A[200005], mark[200005];
std::map<ll, std::vector<int>> occ;

int main() {
  std::cin >> N;
  ll mA = 0;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    mA = std::max(mA, A[i]);
    mark[i] = 1;
    occ[A[i]].push_back(i);
  }

  int ans = N;
  for (int i = 0; i < N; ++i) {
    for (ll x = A[i]; x <= mA; x += A[i]) {
      if (occ.find(x) == occ.end())
        continue;
      for (int j : occ[x]) {
        if (i == j)
          continue;
        if (mark[j])
          ans--;
        mark[j] = 0;
      }
    }
  }

  std::cout << ans << "\n";

  return 0;
}


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

typedef long long ll;

int N;
ll A[200005], mark[200005];
std::map<ll, std::vector<int>> occ;

int main() {
  std::cin >> N;
  ll mA = 0;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    mA = std::max(mA, A[i]);
    mark[i] = 1;
    occ[A[i]].push_back(i);
  }

  int ans = N;
  for (int i = 0; i < N; ++i) {
    if (mark[i] == 0)
      continue;
    if (occ[A[i]].size() > 1) {
      mark[i] = 0;
      ans--;
    }
    for (ll x = A[i]; x <= mA; x += A[i]) {
      if (occ.find(x) == occ.end())
        continue;
      for (int j : occ[x]) {
        if (i == j)
          continue;
        if (mark[j])
          ans--;
        mark[j] = 0;
      }
    }
  }

  std::cout << ans << "\n";

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX int(2 * 10e5)
#define ll long long int
using namespace std;

int main() {
  vector<ll> sieve(MAX + 1, true);
  int n;
  cin >> n;
  vector<ll> arr(n + 1, 0);
  vector<ll> freq(MAX + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    freq[arr[i]] += 1;
  }

  sort(arr.begin(), arr.end());
  ll end = arr[n - 1];
  for (int i = 1; i <= n; i++) {
    int curr = arr[i];
    if (sieve[curr] == false) {
      freq[curr] = 0;
      continue;
    }

    for (ll j = 2; j * i <= end; j++) {
      sieve[curr * j] = false;
    }
    if (freq[curr] > 1)
      sieve[curr] = false;
    freq[curr] = 0;
  }
  ll count = 0;
  for (int i = 1; i <= n; i++) {
    if (sieve[arr[i]] == true)
      count++;
  }
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define MAX int(2 * 10e5)
#define ll long long int
using namespace std;

int main() {
  vector<ll> sieve(MAX + 1, true);
  int n;
  cin >> n;
  vector<ll> arr(n + 1, 0);
  vector<ll> freq(MAX + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    freq[arr[i]] += 1;
  }

  sort(arr.begin(), arr.end());
  ll end = arr[n - 1];
  for (int i = 1; i <= n; i++) {
    int curr = arr[i];
    if (sieve[curr] == false) {
      freq[curr] = 0;
      continue;
    }

    for (ll j = 2; j * curr <= MAX; j++) {
      sieve[curr * j] = false;
    }
    if (freq[curr] > 1)
      sieve[curr] = false;
    freq[curr] = 0;
  }
  ll count = 0;
  for (int i = 1; i <= n; i++) {
    if (sieve[arr[i]] == true)
      count++;
  }
  cout << count << endl;
}
Problem p02642 (C++)

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

vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) cin >> vec[i];
  map<int, int> mp;
  sort(all(vec));
  int cnt = 0;
  set<int> same;
  vector<int> ignore(100001, 0);
  rep(i, n) { ignore[vec[i]]++; }
  rep(i, n) {
    if (ignore[vec[i]] > 1) {
      mp[vec[i]]++;
    }
  }
  rep(i, n) {
    if (ignore[vec[i]] > 1)
      continue;
    vector<int> divs = divisor(vec[i]);
    bool found = false;
    rep(j, divs.size()) {
      if (mp[divs[j]] != 0) {
        found = true;
        break;
      }
    }
    if (!found)
      cnt++;
    mp[vec[i]]++;
  }
  cout << cnt << endl;
  return 0;
}

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

vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) cin >> vec[i];
  map<int, int> mp;
  sort(all(vec));
  int cnt = 0;
  set<int> same;
  vector<int> ignore(1000001, 0);
  rep(i, n) { ignore[vec[i]]++; }
  rep(i, n) {
    if (ignore[vec[i]] > 1) {
      mp[vec[i]]++;
    }
  }
  rep(i, n) {
    if (ignore[vec[i]] > 1)
      continue;
    vector<int> divs = divisor(vec[i]);
    bool found = false;
    rep(j, divs.size()) {
      if (mp[divs[j]] != 0) {
        found = true;
        break;
      }
    }
    if (!found)
      cnt++;
    mp[vec[i]]++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io                                                           \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define fore(i, a, b) for (int i = a; i < b; i++)
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1000005
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

vector<int> bucket(MAX, 0);
bool is(set<int> s, int n) {
  if (bucket[n] >= 2)
    return false;
  for (int i = 1; i * i <= n; i++) {
    if (!(n % i)) {
      if (s.count(i) && i != n)
        return false;
      if (i * i != n) {
        if (s.count(n / i) && (n / i) != n)
          return false;
      }
    }
  }
  return true;
}
int main() {
  optimizar_io int n;
  cin >> n;
  vector<int> v(n);
  set<int> s;
  fore(i, 0, n) {
    cin >> v[i];
    bucket[v[i]]++;
    s.insert(v[i]);
  }
  int cont = 0;
  fore(i, 0, n) {
    if (is(s, v[i]))
      cont++;
  }
  cout << cont << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io                                                           \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define fore(i, a, b) for (int i = a; i < b; i++)
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1000005
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

vector<int> bucket(MAX, 0);
bool is(set<int> &s, int n) {
  if (bucket[n] >= 2)
    return false;
  for (int i = 1; i * i <= n; i++) {
    if (!(n % i)) {
      if (s.count(i) && i != n)
        return false;
      if (i * i != n) {
        if (s.count(n / i) && (n / i) != n)
          return false;
      }
    }
  }
  return true;
}
int main() {
  optimizar_io int n;
  cin >> n;
  vector<int> v(n);
  set<int> s;
  fore(i, 0, n) {
    cin >> v[i];
    bucket[v[i]]++;
    s.insert(v[i]);
  }
  int cont = 0;
  fore(i, 0, n) {
    if (is(s, v[i]))
      cont++;
  }
  cout << cont << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL << 30;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));
  vector<bool> ok(n, false);

  rep(i, n) {
    if (ok[a[i]])
      continue;
    for (int j = 2 * a[i]; j <= a[n - 1]; j += a[i])
      ok[j] = true;
    if (a[i] == a[i + 1])
      ok[a[i]] = true;
  }

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

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL << 30;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));
  vector<bool> ok(1000010, false);

  rep(i, n) {
    if (ok[a[i]])
      continue;
    for (int j = 2 * a[i]; j <= a[n - 1]; j += a[i])
      ok[j] = true;
    if (a[i] == a[i + 1])
      ok[a[i]] = true;
  }

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
// ai/aj!=0(1=<j<=n)
int need[MAXN];
int a[MAXN];
int main() {
  int n;
  int max1 = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), max1 = max(max1, a[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = a[i]; j <= max1; j += a[i]) {
      need[j]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (need[a[i]] == 1)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
// ai/aj!=0(1=<j<=n)
int need[1000005];
int a[MAXN];
int main() {
  int n;
  int max1 = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), max1 = max(max1, a[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = a[i]; j <= max1; j += a[i]) {
      need[j]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (need[a[i]] == 1)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02642 (C++)

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

using namespace std;
const int N = 1e6 + 3;
int main() {
  int n, x;
  cin >> n;
  map<int, int> arr;
  vector<int> v;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    mp[x]++;
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (arr[v[i]] == 0) {
      for (int j = v[i] * 2; j < N; j += v[i]) {
        arr[j]++;
      }
      if (mp[v[i]] <= 1)
        ans++;
    }
  }
  cout << ans;
  return 0;
}


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

using namespace std;
const int N = 1e6 + 3;
int main() {
  int n, x;
  cin >> n;
  map<int, int> arr;
  vector<int> v;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    mp[x]++;
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (arr[v[i]] == 0) {
      for (int j = v[i]; j < N; j += v[i]) {
        arr[j]++;
      }
      if (mp[v[i]] <= 1)
        ans++;
    }
  }
  cout << ans;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <vector>

using namespace std;
#define FOR(it, A) for (auto it = A.begin(); it != A.end(); it++)

int main() {
  int N;
  cin >> N;
  map<int, int> A;
  map<int, int>::iterator it1, it2;
  vector<int> overlapped;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    it1 = A.find(a);
    if (it1 == A.end())
      A.insert(make_pair(a, 0));
    else {
      overlapped.push_back(a);
    }
  }
  int count = 0;
  int gop; // 1부터 곱해나가
  int k;
  FOR(it1, A) { // 작은 것
    // Ai가 A
    // Aj가 B
    if (it1->second == 0) {
      FOR(it2, A) { // 큰 것
        gop = 2;
        k = 0;
        if (it1 != it2) { // 둘이 다를 때
          while (!(k > A.rbegin()->first)) {
            k = it1->first * gop;
            if (k == it2->first) { // 배수의 관계야
              it2->second = 1;     // 큰 거만 1
            }
            gop++;
          }
        }
      }
    }
  }
  FOR(it1, overlapped) {
    it2 = A.find(*it1);
    it2->second = 1;
  }

  FOR(it1, A) {
    if (it1->second == 0)
      count++;
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;
#define FOR(it, A) for (auto it = A.begin(); it != A.end(); it++)

int main() {
  int N;
  cin >> N;
  map<int, int> A;
  map<int, int>::iterator it1, it2;
  vector<int> overlapped;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    it1 = A.find(a);
    if (it1 == A.end())
      A.insert(make_pair(a, 0));
    else {
      overlapped.push_back(a);
    }
  }
  int count = 0;
  int gop; // 1부터 곱해나가
  int k;
  FOR(it1, A) { // 작은 것
    // Ai가 A
    // Aj가 B
    if (it1->second == 0) { // 1이면 이미 누군가의 배수야
      k = 0;
      gop = 2;
      while (!(k > A.rbegin()->first)) {
        k = it1->first * gop;
        it2 = A.find(k);
        if (it2 != A.end())
          it2->second = 1;
        gop++;
      }
    }
  }
  FOR(it1, overlapped) {
    it2 = A.find(*it1);
    it2->second = 1;
  }

  FOR(it1, A) {
    if (it1->second == 0)
      count++;
  }
  cout << count << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):

// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

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

  long n;
  cin >> n;
  vector<bool> sieve(1000001, false);
  vector<long> a(n);
  for (long i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());

  long count = 0;
  for (long i = 0; i < n; i++) {
    if (!sieve[a[i]] && (i == n - 1 || a[i + 1] != a[i]))
      count++;
    long j = a[i];
    while (j <= (long)1e6) {
      sieve[j] = true;
      j += a[i];
    }
  }
  cout << count << "\n";

  return 0;
}


Fixed submission:

// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

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

  long n;
  cin >> n;
  vector<bool> sieve(1000001, false);
  vector<long> a(n);
  for (long i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());

  long count = 0;
  for (long i = 0; i < n; i++) {
    if (!sieve[a[i]] && (i == n - 1 || a[i + 1] != a[i]))
      count++;
    if (!sieve[a[i]]) {
      long j = a[i];
      while (j <= (long)1e6) {
        sieve[j] = true;
        j += a[i];
      }
    }
  }
  cout << count << "\n";

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for (llint(x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for (llint(x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

int n;
int a[200005], cnt[200005];
vector<int> vec[1000005];

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

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

  for (int i = 1; i <= 1000000; i++) {
    for (int j = i; j <= 1000000; j += i)
      vec[j].push_back(i);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    for (int j = 0; j < vec[a[i]].size(); j++) {
      sum += cnt[vec[a[i]][j]];
    }
    if (sum == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for (llint(x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for (llint(x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

int n;
int a[200005], cnt[1000005];
vector<int> vec[1000005];

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

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

  for (int i = 1; i <= 1000000; i++) {
    for (int j = i; j <= 1000000; j += i)
      vec[j].push_back(i);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    for (int j = 0; j < vec[a[i]].size(); j++) {
      sum += cnt[vec[a[i]][j]];
    }
    if (sum == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

int A[200001] = {};
int n_divisor[1000001] = {};

int main() {
  int N;
  std::cin >> N;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }

  for (int i = 1; i <= N; i++) {
    int a = A[i];
    for (int j = 1; a * j <= 1000000; j++) {
      n_divisor[a * j]++;
    }
  }
  int count = 0;
  for (int i = 1; i <= N; i++) {
    if (n_divisor[A[i]] == 1) {
      count++;
    }
  }
  std::cout << count << std::endl;
}

Fixed submission:
#include <iostream>

int A[200001] = {};
int n_divisor[1000001] = {};

int main() {
  int N;
  std::cin >> N;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }

  for (int i = 1; i <= N; i++) {
    n_divisor[A[i]]++;
    if (n_divisor[A[i]] == 1) {
      for (int j = 2; A[i] * j <= 1000000; j++) {
        n_divisor[A[i] * j]++;
      }
    }
  }
  int count = 0;
  for (int i = 1; i <= N; i++) {
    if (n_divisor[A[i]] == 1) {
      count++;
    }
  }
  std::cout << count << std::endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
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;
}
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
const LL mod = 998244353;
const LL LINF = 1LL << 62;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0, -1, 1, 1, -1};
int dy[] = {0, 1, 0, -1, -1, -1, 1, 1};

int main() {
  LL n;
  cin >> n;
  vector<int> a(n);
  map<int, int> ma;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ma[a[i]]++;
  }
  vector<bool> p(1000001, 0);
  for (int i = 1; i <= 1000000; i++) {
    if (ma[i]) {
      for (int j = 2; j * a[i] <= 1000000; j++) {
        p[a[i] * j] = true;
      }
    }
  }
  LL ans = 0;
  for (int i = 0; i < n; i++) {
    if (ma[a[i]] != 1 || p[a[i]])
      continue;
    else
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
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;
}
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
const LL mod = 998244353;
const LL LINF = 1LL << 62;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0, -1, 1, 1, -1};
int dy[] = {0, 1, 0, -1, -1, -1, 1, 1};

int main() {
  LL n;
  cin >> n;
  vector<int> a(n);
  map<int, int> ma;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ma[a[i]]++;
  }
  vector<bool> p(1000001, 0);
  for (int i = 1; i <= 1000000; i++) {
    if (ma[i]) {
      for (int j = 2; j * i <= 1000000; j++) {
        p[i * j] = true;
      }
    }
  }
  LL ans = 0;
  for (int i = 0; i < n; i++) {
    if (ma[a[i]] != 1 || p[a[i]])
      continue;
    else
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#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 MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> a;
  set<int> se;
  for (auto p : mp) {
    if (p.second == 1)
      a.push_back(p.first);
    else {
      int j = 1;
      while (p.first * j <= 1001001) {
        se.insert(p.first * j);
        j++;
      }
    }
  }
  int ans = 0;
  int sz = a.size();
  rep(i, sz) {
    if (!se.count(a[i])) {
      ans++;
      int j = 1;
      while (a[i] * j <= 1001001) {
        se.insert(a[i] * j);
        j++;
      }
    }
  }
  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 MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> a;
  set<int> se;
  for (auto p : mp) {
    if (p.second == 1)
      a.push_back(p.first);
    else {
      if (se.count(p.first))
        continue;
      int j = 1;
      while (p.first * j <= 1001001) {
        se.insert(p.first * j);
        j++;
      }
    }
  }
  int ans = 0;
  int sz = a.size();
  rep(i, sz) {
    if (!se.count(a[i])) {
      ans++;
      int j = 1;
      while (a[i] * j <= 1001001) {
        se.insert(a[i] * j);
        j++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *arr;
  arr = new int[n];
  int rep[1000001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    rep[arr[i]]++;
  }
  int ans = 0;
  sort(arr, arr + n);
  int occ[1000001] = {0};
  for (int i = 0; i < n; i++) {
    if (occ[arr[i]] == 0) {
      for (int j = arr[i] * 2; j < 1000001; j += arr[i])
        occ[j]++;
      if (rep[arr[i]] == 1) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *arr;
  arr = new int[n];
  int rep[1000001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    rep[arr[i]]++;
  }
  int ans = 0;
  sort(arr, arr + n);
  int occ[1000001] = {0};
  for (int i = 0; i < n; i++) {
    if (occ[arr[i]] == 0) {
      for (int j = arr[i]; j < 1000001; j += arr[i])
        occ[j]++;
      if (rep[arr[i]] == 1) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int ky[8] = {-1, 1, -2, 2, -2, 2, -1, 1};
int kx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i <= b; i++)
#define INF 999999999999
const double PI = acos(-1.0);
ll n;
ll a[100000];
ll cnt[1000001];
ll ans;
bool ok[1000001];
ll mx;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> n;
  mx = -INF;
  rep1(i, 0, n) {
    cin >> a[i];
    cnt[a[i]]++;
    mx = max(mx, a[i]);
  }

  rep2(i, 1, mx) {
    if (cnt[i]) {
      for (int j = i + i; j <= mx; j += i)
        ok[j] = true;
    }
  }

  rep1(i, 0, n) if (cnt[a[i]] == 1 && !ok[a[i]]) ans++;

  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int ky[8] = {-1, 1, -2, 2, -2, 2, -1, 1};
int kx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i <= b; i++)
#define INF 999999999999
const double PI = acos(-1.0);
ll n;
ll a[200000];
ll cnt[1000001];
ll ans;
bool ok[1000001];
ll mx;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> n;
  mx = -INF;
  rep1(i, 0, n) {
    cin >> a[i];
    cnt[a[i]]++;
    mx = max(mx, a[i]);
  }

  rep2(i, 1, mx) {
    if (cnt[i]) {
      for (int j = i + i; j <= mx; j += i)
        ok[j] = true;
    }
  }

  rep1(i, 0, n) if (cnt[a[i]] == 1 && !ok[a[i]]) ans++;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;

ll mark[200000];
int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);

  ll maxB = 0;
  for (ll i = 0; i < n; i++)
    if (a[i] > maxB)
      maxB = a[i];

  for (ll i = 0; i < n; i++)
    for (ll x = a[i]; x <= maxB; x += a[i])
      mark[x]++;

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


Fixed submission:
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;

ll mark[20000000];
int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);

  ll maxB = 0;
  for (ll i = 0; i < n; i++)
    if (a[i] > maxB)
      maxB = a[i];

  for (ll i = 0; i < n; i++)
    for (ll x = a[i]; x <= maxB; x += a[i])
      mark[x]++;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
// stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
const int NMAX = 200020;
// 小数点の表し方 cout << fixed << setprecision(5);
vector<long long> enum_divisors(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  // 小さい順に並び替える
  sort(res.begin(), res.end());
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (ma[a[i]] > 1)
      continue;
    vector<ll> p = enum_divisors(a[i]);
    bool ok = true;
    for (auto x : p) {
      if (x == a[i])
        continue;
      if (ma[x] != 0)
        ok = false;
    }
    if (ok) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
// stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
const int NMAX = 3000200;
// 小数点の表し方 cout << fixed << setprecision(5);
vector<long long> enum_divisors(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  // 小さい順に並び替える
  sort(res.begin(), res.end());
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (ma[a[i]] > 1)
      continue;
    vector<ll> p = enum_divisors(a[i]);
    bool ok = true;
    for (auto x : p) {
      if (x == a[i])
        continue;
      if (ma[x] != 0)
        ok = false;
    }
    if (ok) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
vector<int> yakusu;
void dfs(vector<pair<int, int>> &p, int n, int x, int y) {
  if (x == y)
    yakusu.push_back(n);
  else {
    int po = 1;
    for (int i = 0; i <= p[x].second; i++) {
      dfs(p, n * po, x + 1, y);
      po *= p[x].first;
    }
  }
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  vector<int> furui(1000001, 0);
  for (int i = 2; i <= 1000001; i++) {
    if (furui[i] == 0) {
      for (int j = i; j <= 1000001; j += i)
        if (furui[j] == 0)
          furui[j] = i;
    }
  }
  int x = n;
  for (int i = 0; i < n; i++) {
    yakusu.resize(0);
    vector<int> v;
    int I = a[i];
    while (furui[I] != I) { // prime
      v.push_back(furui[I]);
      I /= furui[I];
    }
    v.push_back(I);
    vector<pair<int, int>> p;
    int s = 1, y = 1;
    for (int j = 0; j < v.size() - 1; j++) {
      if (v[j] == v[j + 1])
        s++;
      else {
        p.push_back({v[j], s});
        s = 1;
        y++;
      }
    }
    p.push_back({v.back(), s});
    dfs(p, 1, 0, y);
    for (int j = 0; j < yakusu.size(); j++) {
      if (binary_search(a, a + i, yakusu[j]) ||
          binary_search(a + i + 1, a + n, yakusu[j])) {
        x--;
        break;
      }
    }
  }
  cout << x << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
vector<int> yakusu;
void dfs(vector<pair<int, int>> &p, int n, int x, int y) {
  if (x == y)
    yakusu.push_back(n);
  else {
    int po = 1;
    for (int i = 0; i <= p[x].second; i++) {
      dfs(p, n * po, x + 1, y);
      po *= p[x].first;
    }
  }
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  vector<int> furui(1000001, 0);
  furui[1] = 1;
  for (int i = 2; i <= 1000001; i++) {
    if (furui[i] == 0) {
      for (int j = i; j <= 1000001; j += i)
        if (furui[j] == 0)
          furui[j] = i;
    }
  }
  int x = n;
  for (int i = 0; i < n; i++) {
    yakusu.resize(0);
    vector<int> v;
    int I = a[i];
    while (furui[I] != I) { // prime
      v.push_back(furui[I]);
      I /= furui[I];
    }
    v.push_back(I);
    vector<pair<int, int>> p;
    int s = 1, y = 1;
    for (int j = 0; j < v.size() - 1; j++) {
      if (v[j] == v[j + 1])
        s++;
      else {
        p.push_back({v[j], s});
        s = 1;
        y++;
      }
    }
    p.push_back({v.back(), s});
    dfs(p, 1, 0, y);
    for (int j = 0; j < yakusu.size(); j++) {
      if (binary_search(a, a + i, yakusu[j]) ||
          binary_search(a + i + 1, a + n, yakusu[j])) {
        x--;
        break;
      }
    }
  }
  cout << x << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int, int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 2e5 + 9;

bool tf[mxN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(tf, true, sizeof(tf));
  int n, tmp;
  cin >> n;
  vector<int> v1;
  map<int, int> m1;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    m1[tmp] += 1;
    v1.push_back(tmp);
  }
  int M = *max_element(v1.begin(), v1.end());
  for (auto &c : v1) {
    if (tf[c] == false)
      continue;
    for (int j = 2 * c; j <= M; j += c)
      tf[j] = false;
  }
  ll ans = 0;
  for (auto &c : v1) {
    if (tf[c] && m1[c] == 1)
      ++ans;
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int, int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 1e6 + 9;

bool tf[mxN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(tf, true, sizeof(tf));
  int n, tmp;
  cin >> n;
  vector<int> v1;
  map<int, int> m1;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    m1[tmp] += 1;
    v1.push_back(tmp);
  }
  int M = *max_element(v1.begin(), v1.end());
  for (auto &c : v1) {
    if (tf[c] == false)
      continue;
    for (int j = 2 * c; j <= M; j += c)
      tf[j] = false;
  }
  ll ans = 0;
  for (auto &c : v1) {
    if (tf[c] && m1[c] == 1)
      ++ans;
  }
  cout << ans;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int mx6[] = {1, 0, -1, 1, -1, 0};
int my6[] = {1, 1, 1, 0, 0, -1};
const int N = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int dp[N];
  rep(i, N) dp[i] = 0;

  rep(i, n) {
    if (dp[a[i]] <= 1) {
      int A = a[i];
      for (int j = 0; j < 1000004 && j * a[i] < 1000004; j++) {
        dp[A]++;
        A += a[i];
      }
    }
  }

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


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int mx6[] = {1, 0, -1, 1, -1, 0};
int my6[] = {1, 1, 1, 0, 0, -1};
const int N = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int dp[N];
  rep(i, N) dp[i] = 0;

  rep(i, n) {
    if (dp[a[i]] <= 1) {
      int A = a[i];
      for (int j = 1; j < 1000004 && j * a[i] < 1000004; j++) {
        dp[A * j]++;
      }
    }
  }

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